The following describes standard functions a token contract can implement.
Motivation
Those will allow dapps and wallets to handle tokens across multiple interfaces/dapps.
The most important here are, transfer, balanceOf and the Transfer event.
Specification
Token
Methods
NOTE: An important point is that callers should handle false from returns (bool success). Callers should not assume that false is never returned!
totalSupply
function totalSupply() constant returns (uint256 totalSupply)
Get the total token supply
balanceOf
function balanceOf(address _owner) constant returns (uint256 balance)
Get the account balance of another account with address _owner
transfer
function transfer(address _to, uint256 _value) returns (bool success)
Send _value amount of tokens to address _to
transferFrom
function transferFrom(address _from, address _to, uint256 _value) returns (bool success)
Send _value amount of tokens from address _from to address _to
The transferFrom method is used for a withdraw workflow, allowing contracts to send tokens on your behalf, for example to "deposit" to a contract address and/or to charge fees in sub-currencies; the command should fail unless the _from account has deliberately authorized the sender of the message via some mechanism; we propose these standardized APIs for approval:
approve
function approve(address _spender, uint256 _value) returns (bool success)
Allow _spender to withdraw from your account, multiple times, up to the _value amount. If this function is called again it overwrites the current allowance with _value.
allowance
function allowance(address _owner, address _spender) constant returns (uint256 remaining)
Returns the amount which _spender is still allowed to withdraw from _owner
The final standard can be found here: https://eips.ethereum.org/EIPS/eip-20
Abstract
The following describes standard functions a token contract can implement.
Motivation
Those will allow dapps and wallets to handle tokens across multiple interfaces/dapps.
The most important here are,
transfer
,balanceOf
and theTransfer
event.Specification
Token
Methods
NOTE: An important point is that callers should handle
false
fromreturns (bool success)
. Callers should not assume thatfalse
is never returned!totalSupply
Get the total token supply
balanceOf
Get the account balance of another account with address
_owner
transfer
Send
_value
amount of tokens to address_to
transferFrom
Send
_value
amount of tokens from address_from
to address_to
The
transferFrom
method is used for a withdraw workflow, allowing contracts to send tokens on your behalf, for example to "deposit" to a contract address and/or to charge fees in sub-currencies; the command should fail unless the_from
account has deliberately authorized the sender of the message via some mechanism; we propose these standardized APIs for approval:approve
Allow _spender to withdraw from your account, multiple times, up to the _value amount. If this function is called again it overwrites the current allowance with _value.
allowance
Returns the amount which
_spender
is still allowed to withdraw from_owner
Events
Transfer
Triggered when tokens are transferred.
Approval
Triggered whenever
approve(address _spender, uint256 _value)
is called.History
Historical links related to this standard:
最初由 @frozeman 在 https://github.com/ethereum/EIPs/issues/20 发布