Hwj's blog - Token
type: channel
link: http://blog.hwj.im/index.php/tag/Token/
items: ERC20代币

ERC20代币
type: item
date: 2022-03-17T20:56:59+08:00
description: 一 主要完成以下功能1.自己转账给他人(transfer)2.自己帮别人转账给另外一个人(transferFrom)3.我委托你帮我管理我的代币，使用权给你,但是币还在我这(approve)4.查看一下我还有多少币委托你在管理(allowance)二 规范地址: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md三 方法 function name() public view returns(string) 返回代币名称 function symbol() public view returns (string) 返回代币符号 function decimals() public view returns (uint8) 返回代币的精度(代币可以被分为几份,常用的为8) function totalSupply() public view returns (uint256) 返回总供应量 function balanceOf(address _owner) public view returns (uint256 balance) 返回某个账号里的代币余额 function transfer(address _to, uint256 _value) public returns (bool success) 自己转账给他人(transfer) function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) 自己帮别人转账给另外一个人(transferFrom) function approve(address _spender, uint256 _value) public returns (bool success) 我委托你帮我管理我的代币，使用权给你,但是币还在我这(approve) function allowance(address _owner, address _spender) public view returns (uint256 remaining) 查看一下我还有多少币委托你在管理(allowance)四 事件 event Transfer(address indexed _from, address indexed _to, uint256 _value) 转账时发生 event Approval(address indexed _owner, address indexed _spender, uint256 _value) 委托时发生五 例子一 /* Implements EIP20 token standard: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md .*/ pragma solidity ^0.4.21; import "./EIP20Interface.sol"; contract EIP20 is EIP20Interface { uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; /* NOTE: The following variables are OPTIONAL vanities. One does not have to include them. They allow one to customise the token contract & in no way influences the core functionality. Some wallets/interfaces might not even bother to look at this information. */ string public name; //fancy name: eg Simon Bucks uint8 public decimals; //How many decimals to show. string public symbol; //An identifier: eg SBX function EIP20( uint256 _initialAmount, string _tokenName, uint8 _decimalUnits, st…