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();
};
}
Assuming that the adaylar() function
result[2])view or pure function in Soliditythere 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();