2

If I had an address of a deployed contract, would it be possible to read the contents of any particular storage slot location directly via web3?

1 Answer 1

2

Yes, it's possible to read the contents of any particular storage slot location in a contract as follows:

const contents = await web3.eth.getStorageAt(contractAddress, storageSlotNumber)

Where storageSlotNumber is a number that starts with 0, which would be the slot number for the first storage variable defined in the contract since Solidity maps variables to storage based on the order in which they were declared.

Note that you could also use this to directly read the storage contents of any private or internal storage variable, except for dynamic arrays or mappings since the storage slot location of each element in them is computed as a function of the element's key and the storage slot location of the variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.