Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda