Skip to content

Instantly share code, notes, and snippets.

@daopunk
Created June 30, 2022 21:41
Show Gist options
  • Select an option

  • Save daopunk/daf469585d8969a6ac6fd48a2fe19840 to your computer and use it in GitHub Desktop.

Select an option

Save daopunk/daf469585d8969a6ac6fd48a2fe19840 to your computer and use it in GitHub Desktop.
getMappingItem to access mapping elements in Ethereum state with ethers.js
async function getMappingItem(slot, contractAddress, key) {
const paddedSlot = utils.hexZeroPad(slot, 32);
const paddedKey = utils.hexZeroPad(key, 32);
const itemSlot = utils.keccak256(paddedKey + paddedSlot.slice(2));
return await getUint256(itemSlot, contractAddress);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment