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.

2
  • 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, 2017 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, 2017 at 13:27

2 Answers 2

5

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.

4
  • 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, 2017 at 14:13
  • I guess you have to specify the rate for the smallest unit i.e. 1 ETH / (500 * 10^decimals). Sep 22, 2017 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, 2017 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. Sep 23, 2017 at 6:05
0

Please i am trying to get 500 trillion (500,000,000,000,000) total supply of my token but i dont know what i am doing wrong. below is my code. _decimals is 18

enter code here
uint256 private constant INITIAL_FRAGMENTS_SUPPLY = 10**15 * 10**_decimals;
    uint256 public swapThreshold = (rSupply * 10) / 10000;
    uint256 public rebase_count = 0;
    uint256 public rate;
    uint256 public _totalSupply;
    uint256 private constant MAX_UINT256 = ~uint256(0);
    uint256 private constant MAX_SUPPLY = ~uint128(0);
    uint256 private constant rSupply =
        MAX_UINT256 - (MAX_UINT256 % INITIAL_FRAGMENTS_SUPPLY);
1
  • 1
    If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review Dec 8, 2021 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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