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

120
Views
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 answers
Answer question

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 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!