Skip to content

Instantly share code, notes, and snippets.

@PatrickAlphaC
Created February 22, 2022 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatrickAlphaC/c88baff2443853e333c3bc8e6b362bda to your computer and use it in GitHub Desktop.
Save PatrickAlphaC/c88baff2443853e333c3bc8e6b362bda to your computer and use it in GitHub Desktop.
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