Skip to content

Instantly share code, notes, and snippets.

@KolevDarko
Created April 3, 2023 05:22
Show Gist options
  • Save KolevDarko/2f0e3b790a6f0e600d9a735026f06dfe to your computer and use it in GitHub Desktop.
Save KolevDarko/2f0e3b790a6f0e600d9a735026f06dfe to your computer and use it in GitHub Desktop.
Solidity access mapping
function getMapping(uint256 key) external view returns (uint256 ret) {
uint256 slot;
assembly{
slot := myMapping.slot
}
bytes32 location = keccak256(abi.encode(key, uint256(slot)));
assembly{
ret := sload(location)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment