forked from Medha08/solidity-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathERC20Token(GreenCoin).sol
65 lines (48 loc) · 2 KB
/
ERC20Token(GreenCoin).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
pragma solidity ^0.5.1;
import "browser/Udemy_ERC20.sol";
contract GreenCoin is ERC20Interface{
string public name = "GREENCOIN";
string public symbol ="GRC";
uint public decimals = 0;
uint public supply;
address public founder;
mapping(address => uint) public balances;
mapping(address => mapping(address => uint)) allowed;
event Transfer(address indexed_from,address indexed_to,uint _tokens);
constructor()public payable{
supply = 1000000;
founder = msg.sender;
balances[founder] = supply; // founder has all the tokens initially and he can transfer to other accounts.
}
function totalSupply() public view returns(uint){
return supply;
}
function balanceOf(address _tokenOwner) public view returns(uint balance){
return balances[_tokenOwner];
}
function transfer(address _to,uint _tokens) public returns(bool success){
require(balances[msg.sender]>= _tokens && _tokens > 0);
balances[msg.sender] -= _tokens;
balances[_to] += _tokens;
emit Transfer(msg.sender, _to, _tokens);//log recorded on Blockchain
return true;
}
function allowance(address _tokenOwner, address _spender) public view returns(uint remaining){
return allowed[_tokenOwner][_spender];
}
function approve(address _spender,uint _tokens) public returns(bool success){
require(balances[msg.sender] >= _tokens);
require( _tokens > 0);
allowed[msg.sender][_spender] = _tokens;
emit Approve(msg.sender,_spender, _tokens);
return true;
}
function transferFrom(address _from,address _to,uint _tokens) public returns (bool success){
require(allowed[_from][_to]>= _tokens,"Not allowed");
require(balances[_from] >= _tokens);
balances[_from] -= _tokens;
balances[_to] += _tokens;
allowed[_from][_to] -= _tokens;
return true;
}
}