Skip to content

Instantly share code, notes, and snippets.

@syang-ng
Created Jun 17, 2020
Embed
What would you like to do?
contract ERC20 {
//**********9个函数*******
//1.代币的名字,如:"黑马币"
function name() constant public returns (string name);
//2.代币的简称,例如:HMB
function symbol() public constant returns (string symbol);
//3.代币的最小分割量 token使用的小数点后几位。比如如果设置为3,就是支持0.001表示
function decimals() public constant returns (uint8 decimals);
//4.token的总量
function totalSupply() public constant returns (uint totalSupply);
//5.余额 返回某个地址(账户)的账户余额
function balanceOf(address _owner) public constant returns (uint balance);
/*6.转账 交易代币 从消息发送者账户中往_to账户转数量为_value的token,
从代币合约的调用者地址上转移 _value的数量token到的地址 _to
【注意:并且必须触发Transfer事件】*/
function transfer(address _to, uint _value) public returns (bool success);
/*7.两个地址转账
从账户_from中往账户_to转数量为_value的token,与approve方法配合使用
从地址 _from发送数量为 _value的token到地址 _to
【注意:并且必须触发Transfer事件】
transferFrom方法用于允许合约代理某人转移token。条件是from账户必须经过了approve。*/
function transferFrom(address _from, address _to, uint _value) public returns (bool success);
//8.批准_spender能从合约调用账户中转出数量为_value的token
function approve(address _spender, uint _value) public returns (bool success);
//9.获取_spender可以从账户_owner中转出token的剩余数量
function allowance(address _owner, address _spender) public constant returns (uint remaining);
//**********2个事件*******
//1.发生转账时必须要触发的事件,transfer 和 transferFrom 成功执行时必须触发的事件
event Transfer(address indexed _from, address indexed _to, uint _value);
//2.当函数 approve(address _spender, uint256 _value)成功执行时必须触发的事件
event Approval(address indexed _owner, address indexed _spender, uint _value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment