Created
March 12, 2021 03:18
-
-
Save islishude/59d21e60dea47116f5d0e8d6044a4ef0 to your computer and use it in GitHub Desktop.
test_erc20.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
interface IERC20 { | |
function symbol() external view returns (string memory); | |
function name() external view returns (string memory); | |
function decimals() external view returns (uint8); | |
function totalSupply() external view returns (uint256); | |
function balanceOf(address tokenOwner) | |
external | |
view | |
returns (uint256 balance); | |
function allowance(address tokenOwner, address spender) | |
external | |
view | |
returns (uint256 remaining); | |
function transfer(address to, uint256 tokens) | |
external | |
returns (bool success); | |
function approve(address spender, uint256 tokens) | |
external | |
returns (bool success); | |
function transferFrom( | |
address from, | |
address to, | |
uint256 tokens | |
) external returns (bool success); | |
event Transfer(address indexed from, address indexed to, uint256 tokens); | |
event Approval( | |
address indexed tokenOwner, | |
address indexed spender, | |
uint256 tokens | |
); | |
} | |
contract ERC20 is IERC20 { | |
string public constant override symbol = "ERC20"; | |
string public constant override name = "ERC20 TOKEN EXAMPLE"; | |
uint8 public constant override decimals = 18; | |
uint256 public constant override totalSupply = 1000000 * 10**18; | |
mapping(address => uint256) balances; | |
mapping(address => mapping(address => uint256)) allowed; | |
constructor() { | |
balances[msg.sender] = totalSupply; | |
emit Transfer(address(0), msg.sender, totalSupply); | |
} | |
function balanceOf(address tokenOwner) | |
public | |
view | |
override | |
returns (uint256 balance) | |
{ | |
return balances[tokenOwner]; | |
} | |
function transfer(address to, uint256 tokens) | |
public | |
override | |
returns (bool success) | |
{ | |
balances[msg.sender] -= tokens; | |
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 transferFrom( | |
address from, | |
address to, | |
uint256 tokens | |
) public override returns (bool success) { | |
balances[from] -= tokens; | |
allowed[from][msg.sender] -= tokens; | |
balances[to] += tokens; | |
emit Transfer(from, to, tokens); | |
return true; | |
} | |
function allowance(address tokenOwner, address spender) | |
public | |
view | |
override | |
returns (uint256 remaining) | |
{ | |
return allowed[tokenOwner][spender]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment