With the new TokenGen 3.0 update comes an outstanding smart contract management interface. From it, users will be able to control their smart contract and easily interact with it to perform specific tasks such as pausing/unpausing token transfers, whitelisting/blacklisting addresses, etc. However, there is one thing that we need to clarify about the management interface and that is the raw contract values.
The Contract Management Interface
Before we get to that, let me first show you what the management interface itself looks like:
Of course, there’s more to it as we also load the fundraiser contract below the token contract. But, the above screenshot has everything we need for this tutorial. Now, as you can see, there are five columns in the contract table:
- Entry number – simple counter.
- Name – the name of the variable.
- Raw value – displays the raw value of the variable as it is stored in the contract.
- Natural value – translates the raw value into a more understandable and user-friendly value.
- Action – actions related to each specific variable.
All of the columns are pretty self-explanatory, but the one we are interested in is the raw values and more generally, number values. As you can see, the total supply raw value has a lot of zeros in it, while the natural value of the same variable seems, well, natural. Why are there so many zeros?
This is because of the decimals of the token itself and because of the way the Ethereum network stores numbers. Our Game Token from above has 18 decimals and this means that, if the total supply is 300 tokens (as is in our case), then the value stored in the contract will be 300 with 18 zeros behind it.
Understanding Raw Values
This is why when you go to Etherscan and check your balance for a certain token, you get such a big number with so many zeros. The main reason behind all these zeros is because the Ethereum network cannot store floating point numbers i.e. it cannot store 1.5 or 10.2. But rather, it uses a lot of zeros to split numbers all the way down to 1 wei i.e. the smallest denomination. This is basically the satoshi of the ETH network.
Aside from wei, there also several other denominations that the Ethereum network uses:
- kwei (babbage) – equals 1,000 wei.
- mwei (lovelace) – equals 1,000,000 wei.
- gwei (shannon) – equals 1,000,000,000 wei (1 with 9 zeros behind it).
- microether (szabo) – equals 1,000,000,000,000 wei (1 with 12 zeros behind it).
- milliether (finney) – equals 1,000,000,000,000,000 wei (1 with 15 zeros behind it).
- and of course, ether – equals 1,000,000,000,000,000,000 wei (1 with 18 zeros behind it).
So again, why is this done? Suppose you have 0.1 of our Game Token from above. If you go ahead and check your balance for the token on Etherscan (which returns only raw values), you won’t see the expected 0.1 balance (the natural value), but rather you will see that your balance is 1 with 17 zeros behind it. So, as the token has 18 decimals, the natural value of your balance is 1 with the 17 zeros behind it divided by 1 with 18 zeros behind it i.e. 0.1.
That’s pretty much all there is to raw values and natural values. This is quite simply the way the Ethereum network copes with not storing floating point numbers. Now, it is important to note here that people using the TokenGen contract management interface don’t have to enter raw values when changing anything i.e. gas price limit or individual contribution caps. We translate natural values to raw values automatically under the hood and update the contract accordingly.
Changing Contract Values
So for example, if you want to change the individual max cap for the fundraiser, you would do the following:
We simply enter the new individual max cap as we want it to be in its natural value and then TokenGen takes care of the rest:
As you can see, the raw value was correctly set to 100 with 18 zeros behind it. Of course, TokenGen does this for all number values i.e. gas price limit, individual min cap, etc. The user only needs to enter natural values and not worry about the countless zeros appearing everywhere in their contract.
And that’s pretty much it for this tutorial. On one final note, TokenGen always uses 18 decimals for the tokens it creates because that is the number of decimals used by the Ethereum network as well, so it is much easier to manage such a token as opposed to it having any other number of decimals.
It is also why 18 decimals is the most popular number of decimals for ERC20 tokens, in case you ever wondered. In the end, TokenGen users don’t need to worry about raw values at all, but I wanted to write this short tutorial in case someone ever wondered what’s with all of the zeros in their contract.