referencing the question How to get access to the storage array through the solidity assembler? I have been trying to figure out how to access the mapping (or variable y from the question). The documentation has an example, but of course it has to be overly complicated and access a 2d mapping. However it does say that to get the value of a key (k) of a mapping you hash k . p and load this slot. Does this mean to get the mapping from the similarly asked question you would do:
contract Foo {
uint internal x; // Storage slot #0
mapping (uint => address) internal y; // Storage slot #1
uint [] internal z; // Storage slot #2
function zElement (uint key) public view returns (uint r) {
assembly {
sload(keccak256(add(key, y_slot), 32))
}
}
}
EDIT: fixed the link to go to the correctly mentioned question. EDIT2: should compile now i think.
uint => address
instead ofuint => uint
part?