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

124
Vistas
I can't draw data from smart contract to HTML

This is the error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '1')

Here is the function that I'm using for drawing data from smart contract (and I call this function like getCandidate(1)):

async function getCandidate(cad){
    await myContract.methods.adaylar(cad);{
        var result;
        console.log("result : ", result);
        document.getElementById("cad" + cad).innerHTML = result[1];
        document.getElementById("cad"+cad+'count').innerHTML = result[2].toNumber();
        
    };
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Assuming that the adaylar() function

  • returns an array or a struct with at least 3 items (so that you don't run into "out of bounds" error while accessing result[2])
  • and that it's a view or pure function in Solidity

there are two issues in your code:

The web3js library requires you to explicitly state if you want to make a (read-only) call() or send() a (read-write) transaction. Based on the assumption above, you'll want to make a call:

await myContract.methods.adaylar(cad).call();

This retrieves the returned value but doesn't store it anywhere in the JS code. So you'll need to store it in the result variable in order to access it:

var result = await myContract.methods.adaylar(cad);
console.log("result : ", result);
document.getElementById("cad" + cad).innerHTML = result[1];
document.getElementById("cad"+cad+'count').innerHTML = result[2].toNumber();
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