Solidity: How to Use BalanceOf Function in ERC-20 for EthereumJS

ethereumjssolidity

Is it the number of tokens i have? or just the balance which i need to somehow convert into number of tokens if it is then how can i convert the balance into number of tokens?

Thanks.

Best Answer

The amount of your real balance is the outcome of method balanceOf divided by 10 ** decimals(). Method decimals() returns the number of decimals used to get its user representation.

Example: If balanceOf returns that I have 9000000000000 tokens and the outcome of method decimals is 9 then the "display" variant of my tokens would be 9000000000000 / (10 ** 9) which is 9000 tokens.

If your contract does not have decimals() method then "display" variant of your balance is whatever method balanceOf returns without any additional calculations.

Related Topic