1

I have created and deployed(Remix) a simple contract to understand better data types. When I deploy contract, I see that data types are not in the order inside the contract. Here is my contract:

pragma solidity >=0.8.7;

contract DataTypes {
    uint public uintNumber = 9;
    int public intNumber = -68;
    uint8 public uint8Number = 17;
    bool public myBool = true;
    address public myAddress = msg.sender;
    bytes32 public myBytes32 = "hello byte";
    string public myString = "hello string";
}

And here is the situation after deployment. I expect to see "uint" first, but somehow "int" is coming first and rest is in a complete different order. Do you know the reason for this? Is it something related to Remix or something related to Solidity?

Contract view after deployment

2 Answers 2

0

Is it something related to Remix or something related to Solidity?

Remix just arranges them in the UI in alphanumerical order.

There is no relation to which storage slots each variable inhabits.

I believe the sorting is done in txhelper.ts, here, where each of your variables generates a getter function, which is considered constant. The important line of code is:

return a.name.localeCompare(b.name)
1
  • 1
    I just realized my idiot mistake. True, it is in alphabetical order. And thank you very much for providing deeper information.
    – Abdulhakim
    Mar 10 at 14:21
0

Solidity Compiler automatically rearrange EVM slot wise.In EVM 1 slot size is 32 bytes. If you want to understand how to solidity compiler arrange the storage slot then read the solidity docs.

1
  • Thank you very much for information on EVM slot sizes. That was a topic I didnt know about, I have checked the link you shared and I will further study on it.
    – Abdulhakim
    Mar 10 at 14:23

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.