1

I just started with blockchain programming, I tried experimenting with ethers.js and BSC. While using Token_contract.balanceOf("address") some contacts are giving wrong values, Example correct value is 34.81 while contract returns .000000000034818073, nine zeros added before real value .I am getting this value after correcting the format Wei to Eth const balanceFormatted = ethers.utils.formatUnits(tokholdings, 18); however most of the contract gives exact values after format corrected What could be the reason ?

I am using same abi for all contacts .

const Genabi = [ "constructor(string symbol, string name)", "function transferFrom(address from, address to, uint value)", "function balanceOf(address owner) view returns (uint balance)", "event Transfer(address indexed from, address indexed to, address value)" ];

HFS /FEG contracts have this issue. While fomo /waultx gives correct balance

1 Answer 1

0

You should use decimals() to format the correct balance. Most tokens use 18 (just as ETH) but some of them use 6 , 5 or any other is also possible. So, prior to get balanceof() you should call decimals() so you know how to interpret the output of balanceof()

1
  • Thanks a lot , I kind of got it , I will try and will give a feedback :) Jul 8, 2021 at 15:46

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.