智能合约实战 solidity 语法学习 10 [ 以太坊 ether ERC20标准API介绍及示例 ]name symbol decimals totalSupply balanceOf...

 

1. ERC20代币的标准API

https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md

2. API介绍及示例

interface Token {
    //输入地址,可以获取该地址代币的余额
    function balanceOf(address _owner) external view returns (uint256 balance);

    //将自己的token转账给_to地址,_value为转账个数
    function transfer(address _to, uint256 _value)  external returns (bool success);

    //与approve搭配使用,approve批准之后,调用transferFrom函数来转移token
    function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);

    //批准_spender账户从自己的账户转移_value个token,可以多次转移
    function approve(address _spender  , uint256 _value) external returns (bool success);

    //返回_spender还能转移_owner的token个数
    function allowance(address _owner, address _spender) external view returns (uint256 remaining);    
    /* 
      关于approve、transferFrom、allowance
      账户_owner有100个ETH,想允许_sp
上一篇:如何发布NFT到opensea


下一篇:UniswapV2应用案例分析-beefyUniswapZap.sol