1

What tools or methods exist for querying arbitrary contract storage?

The problem at hand is having to inspect smart contract state variables that have been marked as internal. Block explorers, Remix, and other tools only make it easy to query public state.

Daniel Que
  • 783
  • 7
  • 21
  • Have a look at this post as well: https://ethereum.stackexchange.com/questions/1983/web3-eth-getstorageat-for-mapping/64342 – Alex Byrde Dec 19 '18 at 20:00
  • Crazy how difficult this still is to do https://github.com/ethers-io/ethers.js/discussions/2373#discussioncomment-3600149 – Roman Scher Sep 08 '22 at 20:31

2 Answers2

2

You can open truffle console connected to a public node if you want. Then you can use the api call web3.eth.getStorage(address, slot) to get the data at individual storage slots. I don't know of any tool you can easily plug a smart contract and have it tell you want slot each variable is at, but generally the state variables are in order by declaration. It'll likely vary slightly though.

natewelch_
  • 12,021
  • 1
  • 29
  • 43
0

With 0xweb tool you can install validated contracts locally; one feature is to list and read all variables.

$ npm i 0xweb -g
$ 0xweb i 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 --name USDC --chain eth
$ 0xweb c vars USDC --chain eth
$ 0xweb c var USDC _owner --chain eth

It lists and also reads private variables.

You can also save all state variables of the contract:

0xweb c dump USDC --chain eth

Public nodes are used, that have rate-limits, you should add your rpc node for eth with 0xweb config -e

tenbits
  • 2,304
  • 4
  • 12