NEP-X

May 10, 2024 5:37:51 PM

What is NEP-X?

NEP-X defines what smart contracts must be implemented to be able to receive fungible tokens, like $NEO and $GAS. Contracts that don’t implement the NEP-X standard won’t be able to receive NEP-17 token transfers. Refer to NEP-Y for the non-fungible token callback (NEP-11). This document includes examples of the NEP-X implementation.

If a token tries to transfer tokens to a contract that doesn’t implement the NEP-X standard, an exception will be thrown.

The NEP-X defines a single method, called onNEP17Payment, that accepts three parameters: the sender’s address, the number of tokens sent, and an optional data parameter. The method is called by NEP-17 contracts, after firing the Transfer event. Refer to the NEP-17 page for more information.

NEP-X Code Examples

The following code examples show how to implement the NEP-X standard in different languages. The data parameter is optional and can be of any type. The data parameter is passed from the user when calling the transfer method of the NEP-17 contract.

Simple NEP-X Implementation Example

The most simple NEP-X implementation is a method that accepts the three parameters and does nothing. The method can be empty, but it must be present in the contract. This is enough to be able to receive NEP-17 token transfers.

NEP-X Implementation Example using the Data Parameter

The data parameter allows the user to pass additional information to the contract. This allows the contract to perform different actions based on the data passed. The data parameter can be of any type, but it’s recommended to use maps or serialized objects.

NEP-X Implementation Example using a JSON Object

The Neo blockchain supports native JSON serialization and deserialization. The following example shows how to use a JSON object as the data parameter. Applications can serialize JSON objects and pass them to the NEP-17 contract when calling the transfer method.

The following example shows how to implement the NEP-X standard using a JSON object as the data parameter.