-
Notifications
You must be signed in to change notification settings - Fork 1
/
ERC20.sol
71 lines (57 loc) · 2.42 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
pragma solidity ^0.4.0;
contract Token {
uint256 public totalSupply;
function balanceOf(address _owner) constant returns (uint256 balance);
function transfer(address _to, uint256 value) returns (bool success);
function transferFrom(address _from, address _to, uint256 value) returns (bool success);
function approve(address _spender, uint256 _value) returns (bool success);
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract ERC20Token is Token {
mapping (address=>uint) private _balanceOf;
mapping (address=>mapping (address=>uint)) _allowance;
uint256 public totalSupply = 1000;
address private _owner;
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
function ERC20Token() {
_owner = msg.sender;
_balanceOf[_owner] = totalSupply;
}
function totlaSupply() public returns(uint) {
return totalSupply;
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return _balanceOf[_owner];
}
function transfer(address _to, uint256 value) returns (bool success) {
if (balanceOf(msg.sender) >= value && value > 0 && msg.sender == _owner) {
_balanceOf[msg.sender] -= value;
_balanceOf[_to] += value;
return true;
}else {
return false;
}
}
function transferFrom(address _from, address _to, uint256 value) returns (bool success) {
if (balanceOf(_from) >= value && value > 0 && allowance(_from, msg.sender) >= value) {
_balanceOf[_from] -= value;
_balanceOf[_to] += value;
_allowance[_from][msg.sender] -= value;
Transfer(_from, _to, value);
return true;
}else {
return false;
}
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return _allowance[_owner][_spender];
}
function approve(address _spender, uint256 value) returns (bool success) {
_allowance[msg.sender][_spender] = value;
Approval(msg.sender, _spender, value);
return true;
}
}