1

The following page provides information on how to access a contract's state variables, regardless of who the owner is or what methods are exposed.

http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage

I have been able to follow this for accessing statically sized variables (e.g. uint, address, etc) but can not follow the logic to implement this for others such as mappings and arrays using web3 JS library.

It says:

So for the following contract snippet:

contract C {
  struct s { uint a; uint b; }
  uint x;
  mapping(uint => mapping(uint => s)) data;
}
The position of data[4][9].b is at keccak256(uint256(9) . keccak256(uint256(4) .    uint256(1))) + 1.

I've tried to replicate this using web3.sha3() function but cant get it to work.

  • I've tried to replicate this using web3.sha3() function but cant get it to work., On which OS Soldity installed? – DappDev Feb 28 '17 at 14:57
  • Hello, welcome to Stack Exchange! Please note that the answer section is for posts which actually answer the question. Once you have enough reputation, you will be able to comment everywhere. Until then, please refrain from posting comments as answers. Thank you. – Mithrandir Feb 28 '17 at 15:10
  • Hi DaapDev, This snippet comes from the web page I highlighted. My question is, how is this part implemented using web3?: >> The position of data[4][9].b is at keccak256(uint256(9) . keccak256(uint256(4) . uint256(1))) + 1 – monkia Feb 28 '17 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.