Created
February 22, 2022 12:31
-
-
Save PatrickAlphaC/c88baff2443853e333c3bc8e6b362bda to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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