Storage
Storage Basics
contract YulStorage {
uint x = 2; // slot 0
uint y = 5; // slot 1
uint z = 10; // slot 2
function getXYul() external view returns (uint256 ret) {
assembly {
ret := sload(x.slot)
}
}
function getVarYul(uint256 slot) external view returns (bytes32 ret) {
assembly {
ret := sload(slot)
}
}
// risky, shouldn't be used unless you know what you're doing
function setVarYul(uint256 slot, uint256 value) external {
assembly {
sstore(slot, value)
}
}
} Storage Offsets & Bitshifting
Storage of Arrays & Mappings
Last updated