0

How can we initialize a storage variable to point to a specific storage slot?

Example:

pragma solidity ^0.6.9;

contract SomeContract {
    
    struct SomeStruct {
        uint someUint;
    }
    
    function readFromStorage(uint someParam) external returns (uint) {
        bytes32 slot = keccak256(abi.encodePacked(msg.sender, someParam));
        
        // How can this variable be initialized to point
        // to a struct beginning at storage slot "slot"?
        SomeStruct storage someStruct = *(slot);
        return someStruct.someUint;
    }
}

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.