-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy patherc20.sol
80 lines (71 loc) · 2.23 KB
/
erc20.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
pragma solidity ^0.4.24;
contract ERC20 {
mapping(address => uint256) public balances;
mapping(address => mapping (address => uint256)) public allowed;
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
uint256 private constant MAX_UINT256 = 2**256 -1 ;
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
constructor(
uint256 _initialAmount,
string _tokenName,
uint8 _decimalUnits,
string _tokenSymbol
) public {
balances[msg.sender] = _initialAmount;
totalSupply = _initialAmount;
name = _tokenName;
decimals = _decimalUnits;
symbol = _tokenSymbol;
}
function transfer(
address _to,
uint256 _value
) public returns (bool) {
require(balances[msg.sender] >= _value);
require(msg.sender == _to || balances[_to] <= MAX_UINT256 - _value);
balances[msg.sender] -= _value;
balances[_to] += _value;
emit Transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(
address _from,
address _to,
uint256 _value
) public returns (bool) {
uint256 allowance = allowed[_from][msg.sender];
require(balances[_from] >= _value);
require(_from == _to || balances[_to] <= MAX_UINT256 -_value);
require(allowance >= _value);
balances[_from] -= _value;
balances[_to] += _value;
if (allowance < MAX_UINT256) {
allowed[_from][msg.sender] -= _value;
}
emit Transfer(_from, _to, _value);
return true;
}
function balanceOf(
address _owner
) public view returns (uint256) {
return balances[_owner];
}
function approve(
address _spender,
uint256 _value
) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(
address _owner,
address _spender
) public view returns (uint256) {
return allowed[_owner][_spender];
}
}