This document has a practical approach to storage slots in solidity.
- Contracts:
- Libraries
- StorageSlot.sol
OpenZeppelin
library to easily allocate storage without dealing withassembly
- StorageSlot.sol
- Run a new node
npx hardhat node
hardhat.config.ts
is already set to run all the commands within a local hardhat node, check thedefaultNetwork
key
- Deploy the contracts
npx hardhat run scripts/deploy.ts
- This will generate an
.env
file with the addresses you need to check the storage slots on every contract
- This will generate an
- Now you can test both contracts and check how the storage works
- Storage01 ->
npx hardhat run scripts/lookup-storage-01.ts
- Storage02 ->
npx hardhat run scripts/lookup-storage-02.ts
- If you check the value printed in the console on every script is the same value that we have in our contracts, we’re accessing that value through the storage slot with the
ethers.provider.getStorageAt
method
- Storage01 ->