Created
June 30, 2022 21:41
-
-
Save daopunk/daf469585d8969a6ac6fd48a2fe19840 to your computer and use it in GitHub Desktop.
getMappingItem to access mapping elements in Ethereum state with ethers.js
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
| 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