[英]How to access the value of a mapping variable with Web3
我有一个映射类型的变量,我想从前端访问它的值:
mapping(address => uint) public etherBalanceOf;
我将合同存储在 state
const test = new web3.eth.Contract(test.abi, test.networks[netId].address)
this.setState({test})
并按如下方式进行 web3 调用:
if(this.state.test !== "undfined") {
try {
const depositBalance = await this.state.test.etherBalanceOf.call(this.state.account)
console.log(depositBalance)
} catch(e) {
console.log("Error, checking balance", e)
}
}
但是,我收到一条错误消息:
TypeError:无法读取未定义的属性“调用”
etherBalanceOf
将地址作为参数
代替
const depositBalance = await this.state.test.etherBalanceOf.call(this.state.account)
将地址传递给etherBalanceOf(address)
const depositBalance = await this.state.test.etherBalanceOf(this.state.account).call()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.