4

Is there a specific reason why pretty much everyone uses uint8 for the decimals in ERC20 tokens?

I would get it if it was to limit the size, because the decimals will never be big enough to exceed the uint8 range and therefore uint256 would be a bit overkill...

However, uint256 does actually cost less gas, because it doesn't need to be downscaled like uint8 does.

So I would like to know, is there a specific reason why uint8 would be preferred? Could it mess up some calculations within ERC20 tokens if uint256 is used?

2 Answers 2

4

Well, nothing will mess up if you use uint8 for token decimal. The reason why most of the ERC20 smart contracts use uint8 for the decimal is that because the EIP-20 propose to use uint8 for decimals.

Please check this use. https://eips.ethereum.org/EIPS/eip-20#decimals

Thanks.

0

No , it doesnt mess up the calculations if you use uint256 . In some cases the token details are used as parameter in struct . So if you want to optimize your struct, you can easily do it without changing the other variables . I think this can be one of the reason other reason will be the coding habit, every token decimal is used as a uint8 so everyone is following it.

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.