-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomERC20Token.sol
More file actions
114 lines (82 loc) · 3.07 KB
/
CustomERC20Token.sol
File metadata and controls
114 lines (82 loc) · 3.07 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
contract RasheedToken{
//state variable
string public name;
string public symbol;
uint256 public decimals;
address public owner;
//state*private
uint256 private _totalSupply;
//mappings
mapping(address => uint256) private balances;
mapping(address => mapping(address => uint256)) private allowances;
//Constructor - to be declared before deployment
constructor(uint256 initialSupply){
name = "Rasheed";
symbol = "Rash";
decimals = 18;
owner = msg.sender;
balances[msg.sender] = initialSupply;
//_totalSupply = 5000000;
}
//modifiers
modifier onlyAdmin(){
require(msg.sender == owner, notAdmin());
_;
}
//events
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
//errors
error InsufficientBalance();
error InsufficientFund();
error InvalidAddress();
error AllowanceExceeded();
error notAdmin();
//functions
function totalSupply() public view returns(uint256){
return _totalSupply;
}
function balanceOf(address account) public view returns(uint256){
return balances[account];
}
function transfer(address to, uint256 amount) public returns (bool){
require(balances[msg.sender] >= amount, InsufficientBalance());
require(to != address(0), InvalidAddress());
balances[msg.sender] -= amount;
balances[to] += amount;
emit Transfer(msg.sender, to, amount);
return true;
}
function approve(address spender, uint256 amount) public returns(bool){
allowances[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function allowance(address ownerr, address spender) public view returns (uint256){
return allowances[ownerr][spender];
}
function transferFrom( address from, address to, uint256 amount) public returns (bool){
require(balances[from] >= amount, InsufficientFund());
require(allowances[from][msg.sender] >= amount, AllowanceExceeded());
balances[from] -= amount;
balances[to] += amount;
allowances[from][msg.sender] -= amount;
emit Transfer(from, to, amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public returns(bool){}
function decreaseAllowance(address spender, uint256 subtractedValue) public returns(bool){}
function mint(address to, uint256 amount) public onlyAdmin {
_totalSupply += amount;
balances[to] += amount;
emit Transfer(address(0), to, amount);
}
function burn(address to, uint256 amount) public onlyAdmin {
require(balances[msg.sender] >= amount, "insufficient fund");
_totalSupply -= amount;
balances[to] -= amount;
emit Transfer(to, address(0), amount);
}
}