NRC20
Abstract
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.
function name()symbol
Returns the symbol of the token. E.g. "TK".
// returns string, the symbol of the token
function symbol()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.
totalSupply
Returns the total token supply.
balanceOf
Returns the account balance of a 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.
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.
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.
allowance
Returns the amount which spender is still allowed to withdraw from owner.
Events
transferEvent
MUST trigger when tokens are transferred, including zero value transfers.
A token contract which creates new tokens SHOULD trigger a Transfer event with the from address set to totalSupply when tokens are created.
approveEvent
MUST trigger on any call to approve(spender, currentValue, value).
Implementation
Example implementations are available at
Last updated