-
Notifications
You must be signed in to change notification settings - Fork 0
/
OnlyFrens.sol
60 lines (51 loc) · 2.4 KB
/
OnlyFrens.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
contract MyToken is IERC20 {
string public name = "OnlyFrens";
string public symbol = "FREN";
uint8 public decimals = 18;
uint256 public totalSupply = 6969696969696 * 10**uint256(decimals);
mapping(address => uint256) public balances;
mapping(address => mapping(address => uint256)) public allowed;
constructor() {
balances[msg.sender] = totalSupply;
emit Transfer(address(0), msg.sender, totalSupply);
}
function balanceOf(address account) external view override returns (uint256) {
return balances[account];
}
function transfer(address recipient, uint256 amount) external override returns (bool) {
require(amount <= balances[msg.sender], "Insufficient balance");
balances[msg.sender] -= amount;
balances[recipient] += amount;
emit Transfer(msg.sender, recipient, amount);
return true;
}
function allowance(address owner, address spender) external view override returns (uint256) {
return allowed[owner][spender];
}
function approve(address spender, uint256 amount) external override returns (bool) {
allowed[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) external override returns (bool) {
require(amount <= balances[sender], "Insufficient balance");
require(amount <= allowed[sender][msg.sender], "Insufficient allowance");
balances[sender] -= amount;
balances[recipient] += amount;
allowed[sender][msg.sender] -= amount;
emit Transfer(sender, recipient, amount);
return true;
}
}