0

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.

https://kovan.etherscan.io/tx/0x7b50a2f1a013a0b15eb702f99d09d9a1c16a39bfa179329e246b6ba5b2318b12

0

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:

`100e${decimals}`

More generally, you should:

  • Take input x that you receive from the user, and pass to the contract function:
`${x}e+${decimals}`
  • Take output x that you receive from the contract function, and pass to the user:
`${x}e-${decimals}`
| improve this answer | |

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.