3
totalSupply = initialSupply  *  10  ** uint256(decimals);

Why can't I just put totalSupply = initialSupply?.

I want my address to get all of the tokens and totalSupply to be equal to 1 million.

times 10 and uint256 is just confusing.

If I really need to have that, what should initialSupply be set to in order to have 1 million total supply?

I'm using code from https://ethereum.org/token#the-code (advanced version)

rene
  • 103
  • 3
Uros Tadic
  • 35
  • 1
  • 4

1 Answers1

3

decimals is how many places after the decimal point you want your token to support.

For example, suppose I'm creating a token called "dollars," and I want people to be able to transfer an amount like $1.25. To support that, I'll use a decimals value of 2. Because Solidity only supports integers (no decimal points), inside the contract I'll need to keep track of how many pennies everyone has, not actually dollars. So instead of me sending $1.25, I'll be sending 125¢.

If I want to start out with $1,000,000 in my contract, I'll need to multiply that by 100 to get the number of cents. So initialSupply = 1,000,000, decimals = 2, and thus totalSupply = 1,000,000 * 10**2 = 1,000,000 * 100 = 100,000,000. An initialSupply of $1,000,000 became a totalSupply of 100,000,000¢.

(10**2 means 10 raised to the power of 2.)

If you don't want to support any digits after the decimal point, you can simply set decimals to 0. Note that 10**0 == 1, so you'll just be multiplying by 1, and initalSupply and totalSupply will both be the same.

user19510
  • 27,999
  • 2
  • 30
  • 48
  • I've just created the token and for some reason it had total supply of 1 with 18 zeroes following it.

    So iv decided to burn 1 with 14 zeroes following it.

    Result? https://i.gyazo.com/fe372ac50d3b94c24ed78c79bbacedaa.png

    It still has 18 zeroes but this time its 9999 then 18 zeroes.

    Can you explain me how much is total supply of my token

    – Uros Tadic Oct 23 '17 at 21:27
  • If that was unexpected to you, then this seems like a simple math mistake. It may be simpler to use smaller numbers to see the error. 1 with 4 zeroes following it is 10,000. If you then subtract 1 with 2 zeroes after it (100), the result would be 10,000 - 100 = 9,900. – user19510 Oct 23 '17 at 22:17
  • Oh, sorry, just saw that you said the same number of zeroes were present in both cases. That seems unlikely. You'd have to share the code for your token (including the parameters you set) and how you burned the tokens. – user19510 Oct 23 '17 at 22:20
  • (Also how you are viewing the number of tokens both before and after burning them.) – user19510 Oct 23 '17 at 22:20
  • I am using Ethereum wallet to create a smart contract. I just copy-paste the code from https://ethereum.org/token#the-code (the complete one not minimum viable token)

    I burn the token by going to admin page and selecting burn function, then i wrote amount I wanted to burn. After transaction was done, I came back to admin page and total supply looks even bigger, 18 zeroes still but 9999 in front instead of 1.

    If you could just let me know what parameters I have to write to get total supply of 1 mil with code im using, that would be awesome.

    – Uros Tadic Oct 24 '17 at 09:31
  • I'm not sure what to tell you. If you pass an initialSupply of 1 million (1000000) to the constructor, then you'll have one million coins. Note that the value of totalSupply will be 1000000 followed by 18 zeroes, since the value of decimals is 18. (As I explained above, this is so you can transfer fractions of coins. If you prefer to disallow that, just use 1 as the value for decimals.) – user19510 Oct 24 '17 at 10:02