The following standard allows for the implementation of a standard API for tokens within smart contracts. This standard provides basic functionality to transfer tokens, as well as allows tokens to be approved so they can be spent by another on-chain third party.
Motivation
A standard interface allows that a new token can be created by any application easily : from wallets to decentralized exchanges.
Methods
name
Returns the name of the token - e.g. "MyToken".
// returns string, the name of the token.functionname()
symbol
Returns the symbol of the token. E.g. "TK".
// returns string, the symbol of the token functionsymbol()
decimals
Returns the number of decimals the token uses - e.g. 8, means to divide the token amount by 100000000 to get its user representation.
// returns number, the number of decimals the token usesfunctiondecimals()
totalSupply
Returns the total token supply.
// returns string, the total token supply, the decimal value is decimals* total.functiontotalSupply()
balanceOf
Returns the account balance of a address.
// returns string, the account balance of another account with addressfunctionbalanceOf(address)
transfer
Transfers value amount of tokens to address, and MUST fire the Transfer event. The function SHOULD throw if the from account balance does not have enough tokens to spend.
Note Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event.
// returns `true`, if transfer success, else throw errorfunctiontransfer(address, value)
transferFrom
Transfers value amount of tokens from address from to address to, and MUST fire the Transfer event.
The transferFrom method is used for a withdraw workflow, allowing contracts to transfer tokens on your behalf. This can be used for example to allow a contract to transfer tokens on your behalf and/or to charge fees in sub-currencies. The function SHOULD throw unless the from account has deliberately authorized the sender of the message via some mechanism.
Note Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event.
// returns `true`, if transfer success, else throw errorfunctiontransferFrom(from, to, value)
approve
Allows spender to withdraw from your account multiple times, up the currentValue to the value amount. If this function is called again it overwrites the current allowance with value.
NOTE: To prevent attack vectors, the user needs to give a previous approve value, and the default value that is not approve is 0.