Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
Using ethereum.request to Retrieve Data from Smart Contract in JavaScript

Using javascript, I am currently able to write data to a smart contract I built on the Ethereum Rovan test network using this code (taken from the MetaMask docs)

const transactionParameters = {
    to: '0xacb241f59e1a8c7a61f0781aed7ad067269feb26',
    from: account,
    data: '0xfcc74f71aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
};

const txHash = await ethereum.request({
    method: 'eth_sendTransaction',
    params: [ transactionParameters ],
});

However, I am not able to read data. How can I do this? The hex code of the method for reading data is 0x1f1bd692, so I thought using these parameters would work:

    to: '0xacb241f59e1a8c7a61f0781aed7ad067269feb26',
    from: account,
    data: '0x1f1bd692',

Unfortunately, this just returns the transaction hash, not the data I want from the smart contract.

Note: If possible, please do not suggest any libraries.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here is the solution:

const data = await ethereum.request({
    method: 'eth_getStorageAt',
    params: [ '0xacb241f59e1a8c7a61f0781aed7ad067269feb26', '0x0' ],
})

The first argument in params[] is the address of the contract. The second argument is the index of the item in storage you want to retrieve. It must be a hex number starting with '0x'.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!