Setting the Total Supply

Mar 12, 2024 11:28:29 PM

What is the Total Supply method?

The totalSupply method is part of the standard. It is used to define the total number of tokens that will be available. The totalSupply method returns an integer.

Adding the Total Supply method

Let’s add the totalSupply method to our smart contract. Open the contract file and add the following code to set the total supply to 100 million:

Coin.py

If you are using Go, you will need to include the totalSupply in the safemethods property.

Note that the totalSupply method must be marked as safe to be compatible with the NEP-17 standard. Run the totalSupply method to see if the contract compiles successfully and if the method returns the expected value.

Using Decimals

numbers are represented as integers. The decimals are used to mimic decimal points when the value is shown to the user. For example, if the token has 2 decimals, the value 10000 will be displayed as 100.00.

Let’s update our totalSupply method to use the decimals method:

Coin.py

Testing the Total Supply method

Run the totalSupply method again. It should return the correct value. Since we set the decimals to 8. The returned value should be 100 million followed by 8 zeros.