0

I created own token with 1000000(1 million) total supply, with 18 decimals. When I check _totalSupply in remix it returns 1000000000000000000000000. How is this number converted?

When we have a contract that we want to move some tokens from one account to another which number decimals do we have to use? 1000000000000000000000000 or can we simplify if I want to move 100 tokens?

In truffle I used _totalSupply call to get total supply and it gives me big number.

truffle(bracknell)> rofl._totalSupply.call()

BigNumber { s: 1, e: 24, c: [ 10000000000 ] }

Then I used following to get total supply in human friendly display:

truffle(bracknell)> rofl._totalSupply.call().then(function(balance){console.log(web3.fromWei(balance.toNumber(), "ether")); console.log(balance.toNumber() / Math.pow(10, 18)); })

1000000

1000000

It shows in human friendly, but which number do we use for transfer? I guess big number, in that case what is the easiest way to convert this if we pass for example 100 tokens in function to move them?

1

You should use the number that is multiplied by decimals (10**18). So if you want to transfer one token you pass the value 1000000000000000000. This is because there is not float number representation in solidity and the multiplication by 10**decimals allows you to carry the information about decimal values.

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.