NEP: 5 Title: Token Standard Author: Tyler Adams <[email protected]>, luodanwg <[email protected]>, tanyuan <[email protected]>, Alan Fong <[email protected]> Type: Standard Status: Final Created: 2017-08-10
The NEP-5 Proposal outlines a token standard for the NEO blockchain that will provide systems with a generalized interaction mechanism for tokenized Smart Contracts. This mechanic, along with the justification for each feature are defined. A template and examples are also provided to enable the development community.
As the NEO blockchain scales, Smart Contract deployment and invocation will become increasingly important. Without a standard interaction method, systems will be required to maintain a unique API for each contract, regardless of their similarity to other contracts. Tokenized contracts present themselves as a prime example of this need because their basic operating mechanism is the same. A standard method for interacting with these tokens relieves the entire ecosystem from maintaining a definition for basic operations that are required by every Smart Contract that employs a token.
In the method definitions below, we provide both the definitions of the functions as they are defined in the contract as well as the invoke parameters.
public static BigInteger totalSupply()
Returns the total token supply deployed in the system.
public static string name()
Returns the name of the token. e.g. "MyToken"
.
This method MUST always return the same value every time it is invoked.
public static string symbol()
Returns a short string symbol of the token managed in this contract. e.g. "MYT"
. This symbol SHOULD be short (3-8 characters is recommended), with no whitespace characters or new-lines and SHOULD be limited to the uppercase latin alphabet (i.e. the 26 letters used in English).
This method MUST always return the same value every time it is invoked.
public static byte decimals()
Returns the number of decimals used by the token - e.g. 8
, means to divide the token amount by 100,000,000
to get its user representation.
This method MUST always return the same value every time it is invoked.
public static BigInteger balanceOf(byte[] account)
Returns the token balance of the account
.
The parameter account
SHOULD be a 20-byte address. If not, this method SHOULD throw
an exception.
If the account
is an unused address, this method MUST return 0
.
public static bool transfer(byte[] from, byte[] to, BigInteger amount)
Transfers an amount
of tokens from the from
account to the to
account.
The parameters from
and to
SHOULD be 20-byte addresses. If not, this method SHOULD throw
an exception.
The parameter amount
MUST be greater than or equal to 0
. If not, this method SHOULD throw
an exception.
The function MUST return false
if the from
account balance does not have enough tokens to spend.
If the method succeeds, it MUST fire the transfer
event, and MUST return true
, even if the amount
is 0
, or from
and to
are the same address.
The function SHOULD check whether the from
address equals the caller contract hash. If so, the transfer SHOULD be processed; If not, the function SHOULD use the SYSCALL Neo.Runtime.CheckWitness
to verify the transfer.
If the to
address is a deployed contract, the function SHOULD check the payable
flag of this contract to decide whether it should transfer the tokens to this contract.
If the transfer is not processed, the function SHOULD return false
.
public static event transfer(byte[] from, byte[] to, BigInteger amount)
MUST trigger when tokens are transferred, including zero value transfers.
A token contract which creates new tokens MUST trigger a transfer
event with the from
address set to null
when tokens are created.
A token contract which burns tokens MUST trigger a transfer
event with the to
address set to null
when tokens are burned.