0

I want to get data from on-chain that is not explicitly available through a getter. For example, if I know that there is data at position 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc at address 0xd0A7333587053A5BAe772BD37b9AAe724E367619, how can I retrieve that data if there is no getter function in the contract?

  • Yes, the answer is the same, however the question is being asked is different. Someone may be looking for the answer to this question, but may not find the other questions based on search results. Similarly, a search for the other question would most certainly not produce this question. – Shane Fontaine Jun 11 at 22:56
0

You can retrieve any piece of data from any on-chain contract if you know the location that the data is stored. You can do this by using the getStorage RPC call or through any web3 library.


For your specific question, you can retrieve the data a few ways:

ethers.js

> ethersProvider.getStorageAt('0xd0A7333587053A5BAe772BD37b9AAe724E367619', '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc')

0x00000000000000000000000020af9e54a3670ef6a601bca1f1ec22b1f93cbe23

web3.js:

> web3.eth.getStorageAt('0xd0A7333587053A5BAe772BD37b9AAe724E367619', '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc')

0x00000000000000000000000020af9e54a3670ef6a601bca1f1ec22b1f93cbe23

bash:

> curl -X POST --data '{"jsonrpc":"2.0", "method": "eth_getStorageAt", "params": ["0xd0A7333587053A5BAe772BD37b9AAe724E367619", "0x0", "latest"], "id": 1}' localhost:8545

{"jsonrpc":"2.0","id":1,"result":"0x00000000000000000000000020af9e54a3670ef6a601bca1f1ec22b1f93cbe23"}
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.