0

I am trying to access some values from the contract to display on the front end. I did this by calling some getter methods, only two of the three work and for the third, I get this "Uncaught (in promise) TypeError: Cannot read property 'tronWeb' of undefined" in the console.

Here is the 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;
}

Now here is the solidity code

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];
}

I feel like it's something to do with the block.timestamp, anyone got an idea?

  • where is `window` defined? are you dong this in a browser? – Daniel A. White Apr 12 '19 at 18:07
  • I assume it's something to do with this: https://pastebin.com/mRFh7K1d, same script as the javascript/react. Not sure if I should paste more code or not, I'm going off a template. Also, no this is not in the web, although, the solidity file works perfectly in remix.ethereum but not with tronbox – CryptoGrounds Apr 12 '19 at 18:10
  • Try to replace `window` with `global`, as `window` accessible only in browser's js, and obviously it is `undefined` in your case. – extempl Apr 12 '19 at 18:16
  • Nope, still getting the same error. – CryptoGrounds Apr 12 '19 at 18:37
  • Here is the full js script, it could make more sense to see it all in case i'm missing something: https://pastebin.com/cuUDjbBe – CryptoGrounds Apr 12 '19 at 18:50

0 Answers0