forked from relsi/web3-blockchain-classes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken_diohel.sol
70 lines (56 loc) · 2.53 KB
/
token_diohel.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.7;
//ERC Token Standard #20 Interface
interface ERC20Interface{
function totalSupply() external view returns (uint);
function balanceOf(address tokenOwner) external view returns (uint balance);
function allowance(address tokenOwner, address spender) external view returns (uint remaining);
function transfer(address to, uint tokens) external returns (bool success);
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);
}
//Actual token contract
contract DIOHELToken is ERC20Interface{
string public symbol = "DHEL" ;
string public name = "DHEL Coin";
uint8 public decimals = 2;
uint256 public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
constructor() {
_totalSupply = 1000000;
balances[msg.sender] = _totalSupply;
}
function totalSupply() public override view returns (uint256) {
return _totalSupply;
}
function balanceOf(address tokenOwner) public override view returns (uint256) {
return balances[tokenOwner];
}
function transfer(address to, uint tokens) public override returns (bool success) {
require(tokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender] - tokens;
balances[to] = balances[to] + tokens;
emit Transfer(msg.sender, to, tokens);
return true;
}
function approve(address spender, uint256 tokens) public override returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
function allowance(address tokenOwner, address spender) public override view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function transferFrom(address from, address to, uint256 tokens) public override returns (bool success) {
require(tokens <= balances[msg.sender]);
require(tokens <= allowed[from][msg.sender]);
balances[from] = balances[from] - tokens;
allowed[from][msg.sender] = allowed[from][msg.sender] - tokens;
balances[to] = balances[to] + tokens;
emit Transfer(from, to, tokens);
return true;
}
}