This question already has an answer here:

The documentation at http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage commonly linked to in other questions does not go into enough detail to replicate the process for complex types like dynamic arrays. Following the instructions I to try access my contract storage, I can easily get the first few elementary types but I can't seem to find the right address for a dynamic sized array.

The dynamic array is at index 3 (position 4) and it is an array of struct.

I can easily get the array length with:

web3.eth.getStorageAt(myContractAddress, 3);

But I cannot get any array values using:

var hash = web3.sha3("0x04"), {encoding:"hex"});
web3.eth.getStorageAt(myContractAddress, hash);

I have also tried with "0x4" and "0x3" and "0x5" and many other combinations.

Can someone please provide specific examples using the web3 library to retrieve the address of a dynamic array?

marked as duplicate by eth Jun 27 '16 at 16:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I have restructured the question, please note I have (and did so in the original) added a reference the commonly linked url and mentioned that it is insufficient to solve my problem. Please consider remoing the duplicate tag. – slothbag Jun 27 '16 at 23:08
  • Hi, will let community decide on this. Some things to consider, in addition to the comments I posted in the linked answer. Easiest: Contract can have a function that takes an index and returns the value: example. Otherwise, watch out for the XY problem and getting closed for not creating a minimal, complete example – eth Jun 28 '16 at 0:17