-
Notifications
You must be signed in to change notification settings - Fork 603
Expand file tree
/
Copy pathMyToken.sol
More file actions
57 lines (47 loc) · 1.84 KB
/
MyToken.sol
File metadata and controls
57 lines (47 loc) · 1.84 KB
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
pragma solidity ^0.4.0;
import "browser/ERC20.sol";
contract MyFirstToken is ERC20 {
string public constant symbol = "MFT";
string public constant name = "My First Token";
uint8 public constant decimals = 18;
uint private constant __totalSupply = 1000;
mapping (address => uint) private __balanceOf;
mapping (address => mapping (address => uint)) private __allowances;
constructor() public {
__balanceOf[msg.sender] = __totalSupply;
}
function totalSupply() public constant returns (uint _totalSupply) {
_totalSupply = __totalSupply;
}
function balanceOf(address _addr) public constant returns (uint balance) {
return __balanceOf[_addr];
}
function transfer(address _to, uint _value) public returns (bool success) {
if (_value > 0 && _value <= balanceOf(msg.sender)) {
__balanceOf[msg.sender] -= _value;
__balanceOf[_to] += _value;
return true;
}
return false;
}
function transferFrom(address _from, address _to, uint _value) public returns (bool success) {
if (__allowances[_from][msg.sender] > 0 &&
_value > 0 &&
__allowances[_from][msg.sender] >= _value &&
__balanceOf[_from] >= _value) {
__balanceOf[_from] -= _value;
__balanceOf[_to] += _value;
// Missed from the video
__allowances[_from][msg.sender] -= _value;
return true;
}
return false;
}
function approve(address _spender, uint _value) public returns (bool success) {
__allowances[msg.sender][_spender] = _value;
return true;
}
function allowance(address _owner, address _spender) public constant returns (uint remaining) {
return __allowances[_owner][_spender];
}
}