1

I was wondering if a token implementing ERC20 should return Values in Wei or Ether. Assuming I'm creating ABC token with a 100000 Token Supply & 500 ABC = 1 ETH.

In the ERC20 protocol, for INITIAL_SUPPLY & totalSupply() should we return a wei value of 100000 that would be 100000e18? Also, after deploying, sending 1 ETH to the contract gives out 500e18 tokens

Wallet displays in Wei - Sent little over 1 ETH

How will the exchanges & other wallets display this? Is this something to be handled in the code?

Any help appreciated.

  • Hello I have a problem, I am trying to create token based on ERC 20 token in REMIX compiler i have everything ok bud when i click on start to compile it shows parsererror expected uint8 public decimals .... What can I do about it ? Thank you – Crypto Oct 31 '17 at 10:30
  • 1
    @Crypto I think you should post that as a new question. Hard to say what it is unless you share the code snippet – Sam Nov 1 '17 at 13:27
3

According to the ERC20 standard totalSupply returns an uint. Hence, this should be the amount of tokens in the smallest unit your token offers. This is not in Wei or any Ether unit, this is just the number of tokens (in your smallest unit) which you decide that exist.

Still, your token can specify decimals. For example, if you set uint8 public constant decimals = 8;, your token would support 8 decimal places. But this is only for convenience, i.e. totalSupply still needs to return values in the smallest unit.

For example, let's say you offer 1000 tokens with 2 decimal places. Consequently, totalSupply needs to return 100000 (i.e. 1000 * 100).

By the value of decimals exchanges will know how to display your token. For instance, if someone owns 1337 of your tokens in the smallest unit, the exchange will display it as 13.37 tokens.

EDIT: Note that also all Ether values in solidity smart contracts need to be converted to the smallest Ether unit available, i.e Wei. So if you would issue 500 tokens with 2 decimals for 1 ETH, the price of the smallest unit of your token would be: 1 ether / (500 * 100) = 1e18 / (500 * 100) = 20000000000000.

  • I'm using Zeppelin for getting the token ready, and while deploying via truffle what would be the _rate if I would have to value 500 ABC tokens to 1 ETH - const rate = 500 // rate of ether to ABCToken – Sam Sep 22 '17 at 14:13
  • I guess you have to specify the rate for the smallest unit i.e. 1 ETH / (500 * 10^decimals). – SmCaterpillar Sep 22 '17 at 18:03
  • Wouldn't that add in float? i.e. If we assume 2 decimal, 1 / 500 * 100 = 0.00002 - I'm trying to understand how a 2 decimal be allocated to wei (10e18 ethers) Please bear with me if I'm looking something fundamental – Sam Sep 23 '17 at 2:40
  • Ah ok, no there are no floats in solidity. Internally all smart contracts have to calculate ether values in Wei, i.e. 1 ether = 1e18 wei. So in your case 1e18 / (500 * 100). As a side remark, there exists only integer division in solidity so 12 wei / 5 = 2 wei and the remainder is truncated. – SmCaterpillar Sep 23 '17 at 6:05

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.