AnswerBun.com

How do I get the decimals of an erc20 contract when the decimals variable is not there?

Ethereum Asked by Dylan Kerler on October 24, 2020

What is the best practice for doing this?

In the ERC20 standard having a public decimals: uint256 is marked as optional.
But obviously you cannot display a token balance in the UI without having the decimals.

So how should I handle the case where the decimals field is not there? Should I just assume the contract implements 18 decimals?

What is the standard here? Is it safe to say that 95% of contracts implement the decimals variable?

One Answer

The concept of decimals is purely for user-friendliness - inside the blockchain there are no decimals. That's why it's optional.

If there are no decimals then you simply display what the token amount inside the contract shows - things get easier than with decimals. So it behaves like decimals was 0.

This concept is rather confusing for many people. You can read more for example here: https://ethereum.stackexchange.com/a/72481/31933

Answered by Lauri Peltonen on October 24, 2020

Add your own answers!

Related Questions

TypeError: EthereumTransaction is not a constructor

4  Asked on December 18, 2021 by sreesankar-g-warrier

     

Array of mapping

1  Asked on December 18, 2021 by skytemple

     

How do oracle services work under the hood?

4  Asked on December 16, 2021

 

Can’t deploy on https://wallet.ethereum.org: DAO

1  Asked on December 16, 2021 by anatoly

   

What is the corresponding web3 type to solidity bytes when using Typescript?

1  Asked on December 13, 2021 by suzana-maranho-moreno

 

Error whilst running solidity with python(py-solc)

1  Asked on December 13, 2021 by tabz

   

Access Tuples elements

1  Asked on December 13, 2021 by martasaparicio

   

How can i retrieve the values matching to an id in solidity

3  Asked on December 11, 2021 by venkatesh-muthyala

   

A lot of transactions stuck in local node pool

0  Asked on December 11, 2021 by mahsum-urebe

   

Too much gas consumption

2  Asked on December 9, 2021 by nathan-vasse

   

Parity build error

0  Asked on December 9, 2021 by sylviatrilling

 

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP