Are there any published guidelines on what is the correct order to declare variables in Solidity so that they are optimized from a gas consumption perspective?

Let's say - I need to declare the following variables/types in my smart contract.

string public name;
uint128 public largeNum;
bool public isReady;
bytes32 public ticker;
uint64 public score;
enum STATUS {} ;
struct user {};
mapping (address => uint) users

What would be the best order to declare these variables?

Thanks Sam

1 Answer 1


By storage packing. Give it a read. https://www.adrianhetman.com/unboxing-evm-storage/

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.