-
Notifications
You must be signed in to change notification settings - Fork 5
/
TRC20.sol
188 lines (149 loc) · 5.12 KB
/
TRC20.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
pragma solidity ^0.4.25;
//*******************************************************************//
//------------------------ SafeMath Library -------------------------//
//*******************************************************************//
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0);
uint256 c = a / b;
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
}
//**************************************************************************//
//-------------------------- Token CONTRACT --------------------------//
//**************************************************************************//
contract TRC20Token {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint256 private _decimals;
uint256 private _initialSupply;
address public owner;
event Transfer(
address indexed from,
address indexed to,
uint256 value
);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
constructor() public {
_name = "Token Name";
_symbol = "SYMBOL";
_decimals = 6;
_initialSupply = 35000000;
_totalSupply = _initialSupply * 10**uint256(_decimals);
_balances[msg.sender] = _totalSupply;
owner = msg.sender;
}
modifier onlyOwner(){
require(msg.sender == owner);
_;
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
function decimals() public view returns (uint256) {
return _decimals;
}
function balanceOf(address _owner) external view returns (uint256) {
return _balances[_owner];
}
function allowance(address _owner, address spender) external view returns (uint256) {
return _allowed[_owner][spender];
}
function transfer(address to, uint256 value) external returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
function approve(address spender, uint256 value) public returns (bool) {
require(spender != address(0));
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
function transferFrom(address from, address to, uint256 value) external returns (bool) {
_allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value);
_transfer(from, to, value);
return true;
}
function burn(address _from, uint256 _value) public onlyOwner returns (bool) {
_burn(_from, _value);
return true;
}
function mint(uint256 _value) public onlyOwner returns (bool){
_mint(msg.sender, _value);
return true;
}
function withdraw(address _adminAccount, uint256 _amount) public onlyOwner returns (bool) {
_adminAccount.transfer(_amount);
return true;
}
function getBalance() public view returns(uint256){
return address(this).balance;
}
function transferOwner(address newOwner) public onlyOwner returns (bool) {
require(newOwner != address(0));
owner = newOwner;
emit OwnershipTransferred(owner, newOwner);
return true;
}
function deposit() public payable returns (bool){
return true;
}
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
}