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:

Answered by Lauri Peltonen on October 24, 2020

Add your own answers!

Related Questions

Peering over a direct L2 link without IP addresses

1  Asked on November 18, 2021 by moustafa-ali


What is the maximum size of a struct?

0  Asked on November 18, 2021 by user3316323


Web3js can not touch smart contract, always return 0

1  Asked on November 17, 2021 by will_z


Self-destributing token contract template

2  Asked on November 15, 2021 by vesa


error message when transfer TX

1  Asked on November 15, 2021 by mohammed-jumaa


What is a blockchain oracle?

1  Asked on November 15, 2021 by keenan-olsen


Unknown network ganache

1  Asked on November 12, 2021 by cloudtech-support


Where authorities in PoA are stored?

2  Asked on November 10, 2021 by maroodb


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP