0

Here's my code, including the caller and called contract:

pragma solidity ^0.4.24;

contract Called {
    string info = "default";

    function setInfo(string _info) public {
        info = _info;
    }

    function getInfo() view public returns (string) {
        return info;
    }

}

contract Caller {

    Called called;

    constructor(address addr) public {
        called = Called(addr);
    }

    function setInfo(string _info) public {
        called.setInfo(_info);
    }

    function getInfo() view public returns (string) {
        return called.getInfo();
    }

}

There are two scenarios:

First, I deployed the contracts on my private chain and I set the gas price to be zero on all transactions. Both the setter and getter works well when I invoke them directly in the Called contract.

But when I do it through the Caller contract, the setter works fine while the getter doesn't.

  • When I invoked getter with keyword "view", no error occured but the result I got was a empty string(when the variable is int, then the result would be 0).
  • when I invoked getter without keyword "view", the error message was: Internal JSON-RPC error.

For the second scenario, I deployed them on to Ropsten Test Net and set gas price to be 1 gwei on each transaction. Everything just worked fine.

BTW, I'm using Remix online IDE and MetaMask chrome extension.

It is stated here by GViz that

calling a contract from another contract always requires gas, even if the function is marked view.

Does it have something to do with my issue?

  • what error do you get when trying to execute the getter? – Jaime Aug 2 '18 at 8:13
  • @Jaime, edited my question. – Cyril Cao Aug 2 '18 at 8:25
  • I am running this on remix without any error, I can set and get the information saved using the caller. How are you testing this? – Jaime Aug 2 '18 at 8:28
  • I test this on remix with my current RPC. I spent 0 gas when send transactions directly to the contract and they all worked. But when it comes to getting information through another contract, the problem raises. – Cyril Cao Aug 2 '18 at 8:36
  • If your contract called works, but the caller doesn't work, the only possibility is that the address that you are using to point to the called is not correct (but this should produce an error). You may want to check that. – Jaime Aug 2 '18 at 8:45
0

It turns out to be the issue with the EVM and compiler version. I've tried changing my Solidity compiler version to be 0.4.18 and it worked well.

Here's the issue where I got the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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