-
Notifications
You must be signed in to change notification settings - Fork 0
/
30-ERC-20_GIST_Token.sol
64 lines (46 loc) · 2.13 KB
/
30-ERC-20_GIST_Token.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
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract GIST_Token {
mapping(address => uint256) private s_balances;
mapping(address => mapping(address => uint256)) private s_allowances;
uint256 private s_totalSupply;
string private s_name;
string private s_symbol;
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
constructor() {
s_name = "Guzel Istanbul Token";
s_symbol = "GIST";
s_totalSupply = 100;
s_balances[msg.sender] = s_totalSupply;
}
function name() public view returns (string memory) {return s_name;}
function symbol() public view returns (string memory) {return s_symbol;}
function totalSupply() public view returns (uint256) {return s_totalSupply;}
function balanceOf(address _owner) public view returns (uint256) {return s_balances[_owner];}
function transfer(address _to, uint256 _value) public returns (bool) {
require(s_balances[msg.sender] >= _value, "ERC20: transfer amount exceeds balance");
s_balances[msg.sender] -= _value;
s_balances[_to] += _value;
emit Transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
uint256 currentAllowance = allowance(_from, msg.sender);
require(currentAllowance >= _value, "ERC20: insufficient allowance");
approve(_from, currentAllowance - _value);
require(s_balances[_from] >= _value, "ERC20: transfer amount exceeds balance");
s_balances[_from] -= _value;
s_balances[_to] += _value;
emit Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool) {
s_allowances[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) public view returns (uint256) {
return s_allowances[_owner][_spender];
}
}