Setting the Total Supply

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. It is mandatory and the value can change after the is deployed.

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:

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

Using Decimals

Blockchain tokens are represented as integers. The decimals are used so that the token can be displayed in a more user-friendly format. 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:

Testing the Total Supply method

Run the totalSupply method again. It should return the value 10000000000000000. This is the value we expect, since we set the decimals to 8. The total supply has been set to 100,000,000.00000000 (100 million).