Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda