Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pragma solidity 0.8.7;
contract FunWithStorage {
uint256 public cat;
bytes32 private constant DATA_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
function getData() public view returns (uint256 data) {
bytes32 slot = DATA_SLOT;
assembly {
data := sload(slot)
}
}
function setData(uint newData) public {
bytes32 slot = DATA_SLOT;
assembly {
sstore(slot, newData)
}
}
function getDataAtZero() public view returns (uint256 data) {
assembly {
data := sload(0x0)
}
}
function setCat(uint256 number) public {
cat = number;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment