How to get value of the data at a particular location of a smart contract deployed on RSK?
Asked Answered
D

1

5

I would like to obtain info particular smart contract - that is deployed on the RSK Testnet - to get the data values from its storage. How can I do this? I'm using eth_getStorageAt JSON-RPC, but i'm getting unexpected results.

Dentifrice answered 31/5, 2021 at 9:11 Comment(0)
A
6

To do this, you do indeed use the eth_getStorageAt RPC request. Here's an example:

curl \
  -X POST \
  -H "Content-Type:application/json" \
  --data '{"jsonrpc":"2.0","method":"eth_getStorageAt","params":["0x19f64674d8a5b4e652319f5e239efd3bc969a1fe", "0x1", "latest"],"id":1}' \
  https://public-node.testnet.rsk.co/

This will yield the following response

{
  "jsonrpc": "2.0",
  "id": 1,    "result":"0x0000000000000000000000000000000000000000033b2e3c9fd0803ce8000000"
}

How it works - the eth_getStorageAt RPC takes 3 params:

  • ADDRESS - an address string of the smart contract
  • STORAGE_POSITION - a hexadecimal string for the position in the storage of the smart contract
  • BLOCK_PARAMETER - a hexadecimal string of the integer block number for values at specific blocks, or the string latest for the latest value

The last parameter (BLOCK_PARAMETER) is interesting, as you can use it to query historical values, and see how the data at that location within the storage changes over time, for example.

Acapulco answered 31/5, 2021 at 9:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.