Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

rpc

rsk

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.

like image 697
Owans Avatar asked May 31 '21 09:05

Owans


People also ask

How does truffle interact with smart contract?

In the terminal, code truffle console , which starts a console that enables you to interact with the smart contract. Try all those lines and see if you get the address. If you do, the smart contract is successfully deployed and your project can talk to it.

How do you call a smart contract function?

Call: Reading value from a smart contract You can access an instantiated smart contract methods that you provided the ABI for as follows: yourContract. methods. methodname . By using the call function you'll receive the result of executing the function.

What is a smart contract deployment?

Contract deployment is a special Ethereum transaction sent to the address 0. The deployment has the side effects of creating bytecode at a specific address (i.e, it creates a smart contract account). Contracts are deployed at predictable addresses based on the address and nonce of the account creating the contract.

Where can smart contracts be used?

Other places smart contracts can be utilized include; the Internet of Things, data science and machine learning, and legal contracts Certificate and document forgery has been a significant issue individuals and institutions have faced for years.

What are digital identifier (did) smart contracts?

Digital Identifier (DIDs) smart contracts built on distributed ledger technologies (decentralized) give individuals total control of their data and allow them to share the content of their data as they please, increasing security and reducing the possibility of data mismanagement or a breach.

Are smart contracts the future of Supply Chain Management?

Distributed ledger technologies (DLTs) make smart contracts a good option for administrative payments since they are inexpensive to maintain Supply chain technology built on smart contracts is more effective and can help unlock value and reduce wasted resources


1 Answers

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.

like image 136
bguiz Avatar answered Oct 27 '22 12:10

bguiz