Skip to content

Instantly share code, notes, and snippets.

@Aviksaikat
Created April 18, 2023 13:50
Show Gist options
  • Save Aviksaikat/d41c8f2b72859afc4e11def3709d9cad to your computer and use it in GitHub Desktop.
Save Aviksaikat/d41c8f2b72859afc4e11def3709d9cad to your computer and use it in GitHub Desktop.
Dump the non-zero storage of an Ethereum contract
#!/usr/bin/python3
from brownie import web3
from hexbytes import HexBytes
def display_storage(address, height=100, width=100):
for i in range(100):
# Regular slots
rs = web3.eth.get_storage_at(address, i.to_bytes(32, byteorder="big")).hex()
if rs != "0x0000000000000000000000000000000000000000000000000000000000000000":
print(i, rs)
# Slots for large values
slot = i.to_bytes(32, byteorder="big")
slot_int = int.from_bytes(slot, byteorder="big")
for j in range(100):
s = web3.eth.get_storage_at(
address, "0x" + hex(slot_int + j)[2:].zfill(64)
).hex()
# print(s)
if (
s
!= "0x0000000000000000000000000000000000000000000000000000000000000000"
):
print(i, s)
if __name__ == "__main__":
display_storage("0x876807312079af775c49c916856A2D65f904e612")
@Aviksaikat
Copy link
Author

make sure to add the RPC network in your brownie network

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment