ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
23.06k stars 5.71k forks source link

Can set but not get when calling another contract on private chain #4666

Closed lirycoac closed 6 years ago

lirycoac commented 6 years ago

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.

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.

zhaohongyin commented 6 years ago

I deployed your contracts in Remix online IDE.. Called contract works well but the Caller contract just can get and can not set here is the error message Error: VM Exception while processing transaction: revert BTW, I used ganache and metamask

chriseth commented 6 years ago

Did you set the EVM version of your executing environment to Byzantium? The recent versions of the compiler use some features that are not present in the older EVM versions.

lirycoac commented 6 years ago

@chriseth , Sorry for the delay. I've tried setting the compiler version in Solidity to 0.4.18 and it worked. Thanks!

tanhuiya commented 5 years ago

what about the version after 0.4.18 ?

chriseth commented 5 years ago

@tanhuiya please open a new issue with detailed description.