I have created ERC20 token with 18 decimals. From web3 (application front end) when I transfer 100 tokens, on etherscan it shows 0.0000000000000001 . When I call to get the balance then on UI it shows 100 tokens. How I can fix this?

Method signature: function transfer(address _to, uint256 _value) public returns (bool) { }

The following is a transaction link for reference.


1 Answer 1


When I call to get the balance then on UI it shows 100 tokens.

No, it shows you 100 base units of your token, and since your token decimal-resolution is 18, this is equivalent to 100 / 10 ^ 18 (0.0000000000000001) tokens.

In order to fix this in your web3-based application, replace 100 with "100e18".

If you have decimals at hand, then you can also use:


More generally, you should:

  • Take input x that you receive from the user, and pass to the contract function:
  • Take output x that you receive from the contract function, and pass to the user:
  • 1
    Side note for future readers: Truffle 4.x, which relies on BigNumber, could handle stuff like "100e18". Truffle 5.x, which relies on BN, cannot. Instead, you should do something like new BN(100).mul(new BN(10).pow(new BN(18))), or simply new BN(10).pow(new BN(20)). Nov 17, 2020 at 18:43

Your Answer

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

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