Last active
August 11, 2020 05:28
-
-
Save conr2d/8ac86bdd3504cf84f0fa51d2c4879799 to your computer and use it in GitHub Desktop.
ERC20 interfaces
This file contains 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.4.22 <0.7.0; | |
contract ERC20 { | |
string public name; | |
string public symbol; | |
uint8 public decimals; | |
uint public totalSupply; | |
mapping(address => uint) balances; | |
mapping(address => mapping(address => uint)) allowances; | |
event Transfer(address indexed from, address indexed to, uint value); | |
event Approval(address indexed owner, address indexed spender, uint value); | |
// constructor는 컨트랙트 배포할 때 최초 한 번만 실행됨 | |
// 토큰 이름, 심볼, decimals(소수점 자릿수), 전체 공급량을 각각 name, symbol, decimals, totalSupply에 저장 | |
// totalSupply 만큼의 토큰을 msg.sender에게 발행 (0x0 주소에서 보내는 Transfer 이벤트 발생 필요) | |
constructor(string memory tokenName, string memory tokenSymbol, uint8 tokenDecimals, uint tokenSupply) public { | |
} | |
// owner가 가진 토큰의 양 조회 | |
function balanceOf(address owner) public view returns (uint) { | |
} | |
// msg.sender가 가진 토큰을 to에게 전송 | |
// Transfer 이벤트 발생 필요 | |
function transfer(address to, uint value) public returns (bool) { | |
} | |
// from이 가진 토큰을 to에게 전송 | |
// 전송하고자 하는 value보다 approve된 값이 더 커야함 | |
// Transfer 이벤트 발생 필요 | |
// (선택사항) Approval 이벤트 발생 필요 | |
function transferFrom(address from, address to, uint value) public returns (bool) { | |
} | |
// owner의 토큰을 spender가 꺼내갈 수 있도록 허용된 양 조회 | |
function allowance(address owner, address spender) public view returns (uint) { | |
} | |
// msg.sender의 토큰을 spender가 꺼내갈 수 있도록 (transferFrom) 승인, allowances를 증가시켜 구현 | |
// Approval 이벤트 발생 필요 | |
function approve(address spender, uint value) public returns (bool) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment