NEP17

May 14, 2024 2:47:57 PM

What is NEP-17?

NEP-17 is a for creating fungible tokens on the . It is similar to the standard on Ethereum. By following the NEP-17 standard developers can ensure that their is compatible with existing and future applications. A complete implementation of the NEP-17 standard can be found at the end of this page.

The standard defines how a should be implemented on the Neo blockchain, but it doesn’t dictate the token’s use case. The implementation details are left to the developer, allowing flexibility in creating different types of tokens.

To create a NEP-17 token, developers must implement the required methods and events. The contract metadata should include the NEP-17 standard and permissions to call the onNEP17Payment method on other contracts.

Payable Contracts

Any contract that needs to accept incoming tokens must implement the onNEP17Payment . This callback is triggered when tokens are transferred to the contract. If the contract does not implement this callback, it will not be able to receive tokens. Note that the onNEP17Payment method is implemented on the recipient contract, not the token contract.

NEP-17 Standard

The NEP-17 standard defines the interface for a fungible token on the Neo blockchain. It defines the following methods:

  • symbol - Returns the symbol of the token.
  • decimals - Returns the number of decimals used by the token.
  • totalSupply - Returns the total supply of the token.
  • balanceOf - Returns the balance of the specified .
  • transfer - Transfers tokens from one account to another.

The NEP-17 standard also defines the following event and callback:

  • Transfer - Triggered when tokens are transferred from one account to another.
  • onNEP17Payment - Callback invoked when tokens are transferred to a smart contract.

NEP-17 Symbol Method

Returns the symbol of the token. The symbol does not need to be unique. The symbol is used by wallets and other applications. Visit the for more information. NEO and GAS are examples of symbols.

  • This method must be marked as Safe.
  • The number of decimals must not change over time.
  • Uppercase symbols are recommended.

NEP-17 Decimals Method

Returns the number of decimals used by the token. This is 8 for NEO and 0 for GAS. The value returned by decimals is used to offset the decimal point when displaying the token balance.

For example, if the number of decimals is 8, a balance of 100000000 is displayed as 1.0. Internally, all operations are performed using integers. Visit the page for more information.

  • This method must be marked as Safe.
  • The number of decimals must not change over time and can be hard coded.

NEP-17 Total Supply Method

Returns the total supply of the token. This is the total number of tokens that exist. This may include locked tokens and tokens that are not in circulation. The total supply may change over time. Visit the page for more information.

  • This method must be marked as safe.
  • The total supply can be a constant value or calculated based on the current state of the contract.

NEP-17 Balance Of Method

Returns the balance of the specified account.

  • This method must be marked as safe.

NEP-17 Transfer Method

Transfers tokens from one account to another.

  • If the recipient is a smart contract, the contract must implement the onNEP17Payment callback.
  • If the transfer is successful, the contract must trigger the Transfer event.
    • The Transfer event must be triggered even when minting or burning tokens.
  • The method must start with lowercase t and be named transfer.
    • The Neo C# compiler will automatically convert the method name to lowercase.
  • The data parameter is used to pass additional information on to the recipient of the contract.
    • The data parameter can be null if no additional information is required.

NEP-17 Transfer Event

The Transfer event is triggered when tokens are transferred from one account to another.

  • This event must triggered when tokens are minted or burned.

NEP-17 onNEP17Payment Callback

The NEP-17 standard states that the contract must check if the recipient is a smart contract and call the onNEP17Payment callback if it is.

The onNEP17Payment is implemented on the recipient contract and not in the token contract. The recipient contract must implement the onNEP17Payment method with the following :

The implementation of the onNEP17Payment method is specific to the recipient contract and can include any logic required to handle incoming tokens.

It’s common for contracts implementing the onNEP17Payment method to check which token is being transferred and take appropriate actions based on the token type. This is done by checking the Calling Script Hash and comparing it to the whitelist of accepted tokens. The Calling Script Hash is part of the Runtime package.

If the recipient contract does not implement the onNEP17Payment method, an exception will be thrown, and the token transfer will be rejected. Note that even if it fails, the transaction will still be recorded on the blockchain.

Full NEP-17 Example

The following is a full example of a NEP-17 token contract. The examples are provided in Python, C#, Java and Go. The contract mints 100 MM tokens with 8 decimals when deployed. The tokens are sent to the sender’s address, and the sender is set as the owner of the contract.

The example doesn’t include the implementation of the onNEP17Payment method in the recipient contract. Visit the NEP-11 page for examples of the onNEP17Payment method implementation.