我正在尝试访问合同中的某些值以显示在前端。我通过调用一些吸气剂方法做到了这一点,三个方法中只有两个起作用,而对于第三个方法,我在控制台中收到“未捕获(承诺)TypeError:无法读取未定义的'tronWeb'属性”。
这是Javascript / React
await Utils.setTronWeb(window.tronWeb, contractAddress);
...
// this one works
async getTron2Balance()
{
const bal = (await Utils.contract.getMyTron2().call()).toNumber();
console.log("Tron² Balance:", bal);
document.getElementById("tron2").innerHTML = bal;
this.getMicroTronBalance();
}
// this one doesn't
async getMicroTronBalance()
{
const bal = (await Utils.contract.getMyMicroTron().call()).toNumber();
console.log("MicroTron Balance:", bal);
document.getElementById("microTron").innerHTML = bal;
}
现在是坚固性代码
function getMyTron2() public
view
returns
(uint256)
{
return safeTron[msg.sender];
}
function getMyMicroTron() public
view
returns
(uint256)
{
updatePlayersMicroTron(msg.sender);
tempOldTime = block.timestamp;
return rewardedMicroTron[msg.sender];
}
我觉得这与block.timestamp有关,有人知道吗?