我可以从智能合约到html绘制数据
这是错误:
undured(在承诺中)TypeError:无法读取未定义的属性(读取'1')
这是我正在使用的功能来绘制智能合约的数据(我称此功能为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();
};
}
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();
};
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设
adaylar()
函数结果[2] <时,您不会遇到“限制”错误。 /code>)
view
或纯
固体中的功能,您的代码中有两个问题:
web3js 库库要求您明确说明(如果您要制作(只读)
call> call()
或send> send()
send()< /code> a(读写)事务。基于上面的假设,您需要拨打电话:这将检索返回的值,但不会将其存储在JS代码中。因此,您需要将其存储在
result
变量中以访问它:Assuming that the
adaylar()
functionresult[2]
)view
orpure
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()
orsend()
a (read-write) transaction. Based on the assumption above, you'll want to make a 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: