-
Notifications
You must be signed in to change notification settings - Fork 0
/
MFET.sol
86 lines (60 loc) · 2.74 KB
/
MFET.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
// SPDX-License-Identifier: Unlicansed
pragma solidity ^0.8.7;
// ----------------------------------------------------------------------------
// EIP-20: ERC-20 Token Standard
// https://eips.ethereum.org/EIPS/eip-20
// -----------------------------------------
interface ERC20Interface {
function totalSupply() external view returns (uint);
function balanceOf(address tokenOwner) external view returns (uint balance);
function transfer(address to, uint tokens) external returns (bool success);
function allowance(address tokenOwner, address spender) external view returns (uint remaining);
function approve(address spender, uint tokens) external returns (bool success);
function transferFrom(address from, address to, uint tokens) external returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
contract Cryptos is ERC20Interface{
string public name = "Cryptos";
string public symbol = "CRPT";
uint public decimals = 0; //18 is very common
uint public override totalSupply;
address public founder;
mapping(address => uint) public balances;
// balances[0x1111...] = 100;
mapping(address => mapping(address => uint)) allowed;
// allowed[0x111][0x222] = 100;
constructor(){
totalSupply = 1000000;
founder = msg.sender;
balances[founder] = totalSupply;
}
function balanceOf(address tokenOwner) public view override returns (uint balance){
return balances[tokenOwner];
}
function transfer(address to, uint tokens) public override returns(bool success){
require(balances[msg.sender] >= tokens);
balances[to] += tokens;
balances[msg.sender] -= tokens;
emit Transfer(msg.sender, to, tokens);
return true;
}
function allowance(address tokenOwner, address spender) view public override returns(uint){
return allowed[tokenOwner][spender];
}
function approve(address spender, uint tokens) public override returns (bool success){
require(balances[msg.sender] >= tokens);
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
function transferFrom(address from, address to, uint tokens) public override returns (bool success){
require(allowed[from][to] >= tokens);
require(balances[from] >= tokens);
balances[from] -= tokens;
balances[to] += tokens;
allowed[from][to] -= tokens;
return true;
}
}