• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

88
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 3 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 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error