1

Why do people use uint8 for constant variables such as decimals for tokens, isn't it better to use uint256? the EVM would need to use additional calls to go from 256/32bits to 8 and therefore increase gas costs

1

With optimization enabled, there will be no extra gas cost for using uint8 constants instead of uint256 constants. The conversion instructions are optimized away entirely.

With optimization disabled, there is a small extra gas cost.

I just tested it, and with optimization disabled the use of a uint8 constant gave 3 bytes of bytecode more than the use of a uint256 constant.

With optimization enabled, the Solidity compiler gives the exact same bytecode in both cases.

1
  • 1
    why is it important to specify uint type anymore then? one could just go with uint right – NemesisChain Oct 7 '17 at 23:07

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.