我正在尝试从合同中访问一些值以显示在前端。我通过调用一些 getter 方法来做到这一点,这三个方法中只有两个有效,第三个方法是在控制台中得到这个“Uncaught (in promise) TypeError: Cannot read property 'tronWeb' of undefined”。
这是 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;
}
现在这是solidity代码
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有关,有人知道吗?