1

having a problem with calling a method of my deployed contract in the main Ethereum network.

I have a 'view' function which returns user's refund balance, everything worked fine in my local blockchain (Ganache), but doesn't work in the main network :(

So here I call that method from web3:

this.myContract.methods.checkFunds().call().then((refunds) => {
      return refunds;
});

this is my contract function and here I call another contract function:

mapping(address => uint256) private funds;

function checkFunds() external view returns(uint256) {
    return contract2.checkFunds(msg.sender);
}

here is that contract2:

function checkFunds(address _owner) public view returns(uint256) {
    return funds[_owner];
}

if user doesn't have funds then it should return 0 and it's uint256, then it should be ok, but I get such an error:

Uncaught (in promise) Error: Returned values aren't valid, did it run Out of Gas?
at ABICoder.decodeParameters (app.js:37038)
at Contract._decodeMethodReturn (app.js:36366)
at Method.outputFormatter (app.js:36719)
at Method.formatOutput (app.js:9201)
at sendTxCallback (app.js:9511)
at app.js:96628
at inpage.js:1
at inpage.js:1
at o (inpage.js:1)
at inpage.js:1

and I have the latest version of web3 btw:"react-web3": "1.2.0",

Do view functions cost gas ? That's strange, because I call another method of that contract to read items and it doesn't cost anything.

thank you!

  • The error printout is misleading (you), because a view function does not require any gas in order to execute it. It is merely a "peek" into the blockchain data (i.e., no mining is performed). – goodvibration Dec 25 '18 at 12:23
  • I suggest that in your contract, check if contract2 is initialized correctly. – goodvibration Dec 25 '18 at 12:24
  • @goodvibration thank you for your reply. It's also in the main network and I have already tried to call it's functions, so the problem in this one only. Checked it in etherscan, it's also there, so that function exists and it's view one there – Costa Rassco Dec 25 '18 at 12:28
  • Make sure that you are calling the function checkFunds() other contract, not of contract2. – Mahesh Rajput Dec 25 '18 at 12:28
  • Well, is contract2 deployed on the main network? – goodvibration Dec 25 '18 at 12:28
0

You're doing a call(), without setting the msg.sender. Try to add the addr as a param to the checkFunds() function, modify the web3 call accordingly and see if that fixes it.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.