0

This question is twofold:

The standard number of decimals for an ERC20 token is 18. If we lower this number, can we expect decreased gas costs when creating/transferring the token, since this should consume less memory in EVM?

If so, why do most tokens follow the 18 decimal standard? For most use cases this level of precision is unnecessarily large, by orders of magnitude.

0

No, you will not consume less memory in the EVM.

Per the ERC20 spec, decimals must be a uint8. Because of this, the actual decimals variable will always be the same cost.

Additionally, you will not have any cost savings by storing variables of token values with a smaller decimals. In fact, it may even cost more to store a smaller value (such as uint128). This is because the EVM is expecting to see a uint256 and has to do more work if it is given anything different. From the docs:

When using elements that are smaller than 32 bytes, your contract’s gas usage may be higher. This is because the EVM operates on 32 bytes at a time. Therefore, if the element is smaller than that, the EVM must use more operations in order to reduce the size of the element from 32 bytes to the desired size.

Using 18 decimals is not defined in the spec, but it is common practice. Many dapp developers have programmed for 18 decimals, and there have been many instances where less have caused bugs. With this said, you may use whatever number you desire.

| improve this answer | |
  • 1
    Thanks for the thorough response. Would you say that most ERC20s are relatively the same in terms of gas usage for minting/transferring? I am interested in building as lightweight a token as possible. – wass Jan 9 at 2:53
  • Yes. The logic within the functions are relatively standard. There is not much you can do to lighten them up without breaking spec. – Shane Fontaine Jan 9 at 2:59

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.