-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSafeYorkERC20Token.sol
79 lines (61 loc) · 2.75 KB
/
SafeYorkERC20Token.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.10;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol";
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
contract YorkERC20Token is IERC20{
// use SafeMath library
using SafeMath for uint256;
// Track how many tokens are owned by each address.
mapping (address => uint256) public override balanceOf;
string public name = "York Token";
string public symbol = "YTN";
uint8 public decimals = 18;
uint256 public override totalSupply = 1000000 * (uint256(10) ** decimals);
event Transfer(address indexed from, address indexed to, uint256 value);
constructor() public {
// Initially assign all tokens to the contract's
// creator.
balanceOf[msg.sender] = totalSupply;
emit Transfer(address(0), msg.sender, totalSupply);
}
function transfer(address to, uint256 value) public override returns (bool success) {
require(balanceOf[msg.sender] >= value);
balanceOf[msg.sender] = balanceOf[msg.sender].sub(value); // deduct from
// sender's balance
balanceOf[to] = balanceOf[to].add(value); //
// add to recipient's balance
emit Transfer(msg.sender, to, value);
return true;
}
event Approval(address indexed owner, address indexed spender, uint256 value);
mapping(address => mapping(address => uint256)) public override allowance;
function approve(address spender, uint256 value)
public override
returns (bool success)
{
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
function transferFrom(address from, address to, uint256 value)
public override
returns (bool success)
{
require(value <= balanceOf[from]);
require(value <= allowance[from][msg.sender]);
balanceOf[from] = balanceOf[from].sub(value);
balanceOf[to] = balanceOf[to].add(value);
allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
emit Transfer(from, to, value);
return true;
}
}