0

What is the correct way to get the number of decimals using web3? For example, how would I get the number 6 as a result when trying to obtain USDT decimals from the contract address?

I was using contract.methods.decimals().call() but it returns this

RETURN VALUE I GET { [Function: bound _executeMethod] request: [Function: bound _executeMethod] }

async getTokenInfo(tx) {
try {
  const contract = new web3.eth.Contract(abi, tx.to);
  const symbol = await contract.methods.symbol().call();
  const decimals = await contract.methods.decimals().call;

  return { symbol: symbol, decimals: decimals };
} catch (error) {
  console.log("getTokenInfo", error);
}
3
  • It should actually works. From where come „contract“ can you show how u assign the value to the contract variable
    – Majd TL
    May 9 at 9:51
  • And have u used await before that ....call()
    – Majd TL
    May 9 at 9:52
  • Im using await with it. I use the abi from the package human-standard-token-abi and the message I obtain the decimals (or want to is this). The symbols are working correctly, decimals not. async getTokenInfo(tx) { try { const contract = new web3.eth.Contract(abi, tx.to); const symbol = await contract.methods.symbol().call(); const decimals = await contract.methods.decimals().call; return { symbol: symbol, decimals: decimals }; } catch (error) { console.log("getTokenInfo", error); } }
    – Chris S
    May 9 at 14:19
0

nevermind guys, I forgot the "()" after the call...

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.