Skip to content

Instantly share code, notes, and snippets.

@KolevDarko
Created March 29, 2023 10:13
Show Gist options
  • Save KolevDarko/1abb0d30de305f79048cbe9af264eb8b to your computer and use it in GitHub Desktop.
Save KolevDarko/1abb0d30de305f79048cbe9af264eb8b to your computer and use it in GitHub Desktop.
Storage basics
//SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
contract StorageBasics {
uint256 x = 1;
uint256 y = 23;
uint256 z = 48;
uint128 a = 1;
uint128 b = 2;
function getXYul() external view returns (bytes32 ret) {
assembly {
ret := sload(x.slot)
}
}
function getSlot(uint256 slot) external view returns (bytes32 ret) {
assembly {
ret := sload(slot)
}
}
// dangerous operation, never allow external actors to set arbitrary slot values
function setSlot(uint256 slot, uint256 value) external {
assembly {
sstore(slot, value)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment