Adding Symbol and Decimals to the NEP-17 Smart Contract

Mar 12, 2024 11:28:29 PM

What are the Symbol and Decimal methods?

The symbol and decimals methods are part of the standard. They are used to define the token’s symbol and the number of decimals it uses. The symbol method returns a string, while the decimals method returns an integer. Both methods are mandatory and should not change after the token is deployed.

Adding the Symbol and Decimals methods

Let’s add the symbol and decimals methods to our smart contract. Open the contract file and add the following code:

Make sure you save the file after making these changes.

Testing the Symbol and Decimals methods

Start testing your contract by running the symbol method. The output should be the string COIN:

Next, run the decimals method. The output should be the integer 8:

Making the Symbol and Decimals methods read-only

The standard implies that the symbol and decimals methods should be read-only. This means that they should not make changes to the storage. Let’s fix this before we continue.

Update the symbol and decimals methods to be read-only:

Golang users must update the Coin.yml file to include the safemethods attribute:

Coin.yml