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

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()

2
  • Thanks a lot , I kind of got it , I will try and will give a feedback :) Jul 8 '21 at 15:46
  • Yes it worked . Thanks again Jul 8 '21 at 17:11

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.