[Ethereum] Should INITIAL_SUPPLY & totalSupply be returned in Wei

openzeppelinsoliditytokens

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.

Best Answer

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.