Skip to content

Instantly share code, notes, and snippets.

@veridelisi
Created March 1, 2023 11:56
Show Gist options
  • Save veridelisi/51a43d9be696f5c34a3d4da2d608f5db to your computer and use it in GitHub Desktop.
Save veridelisi/51a43d9be696f5c34a3d4da2d608f5db to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract StorageContract {
uint256 a = 9; // Slot 0
uint256 b = 8; // Slot 1
uint256 c = 7; // Slot 2
uint256 d = 6; // Slot 3
function readStorageSlot0(uint yournumber) public view returns (bytes32 result) {
assembly {
result := sload(yournumber)
}
}
function getSlotNumbers() public pure returns(uint256 slotA, uint256 slotB, uint256 slotC, uint256 slotD) {
assembly {
slotA := a.slot
slotB := b.slot
slotC := c.slot
slotD := d.slot
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment