20181118————创建自己的数字货币

ERC20 Token
也许你经常看到ERC20和代币一同出现, ERC20是以太坊定义的一个代币标准。
要求我们在实现代币的时候必须要遵守的协议,如指定代币名称、总量、实现代币交易函数等,只有支持了协议才能被以太坊钱包支持。
接口如下

contract ERC20Interface {

    string public constant name = "Token Name";
    string public constant symbol = "SYM";
    uint8 public constant decimals = 18;  // 18 is the most common number of decimal places

    function totalSupply() public constant returns (uint);
    function balanceOf(address tokenOwner) public constant returns (uint balance);
    function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
    function transfer(address to, uint tokens) public returns (bool success);
    function approve(address spender, uint tokens) public returns (bool success);
    function transferFrom(address from, address to, uint tokens) public returns (bool success);

    event Transfer(address indexed from, address indexed to, uint tokens);
    event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}

name:代币名称
symbol:代币符号
decimals:代币小数点位数,代币最小的单位,18单位表示我们可以拥有.0000000000000000001单位个代币
totalSupply():发行代币总量
balanceOf():查看对应账号的代币余额
transfer():实现代币交易,用于给用户发送代币(从我们的账户里)
transferFrom():实现代币用户之间的交易
allowance():控制代币的交易,如何交易账号及资产
approve():允许用户花费的代币数量

猜你喜欢

转载自blog.csdn.net/qq_36344771/article/details/84198207