0

I have simple code that deploys and calls method from other contract. I am always getting 0 (by calling Test.get()) instead of the actual value from the other contract. I am using Geth 1.8.11 (private network, only single node) and Remix IDE.

pragma solidity ^0.4.17;

  contract Test {

    address public d_address;
    function deployOther() public {
        d_address = new Referred(123);
    }

    function get() public returns (uint){
        return Referred(d_address).toReturn();
    }
    function set() public payable {
        Referred(d_address).set.gas(21000).value(msg.value)(456);
    }

}

contract Referred {
    uint public val;
    constructor(uint v) public {
        val = v;
    }

    function set(uint nv) public payable{
        val = nv;
    }

    function toReturn() public view returns (uint){
        return val;
    }
}

I see this error in the geth log,

DEBUG[06-25|19:34:00|core/state_transition.go:216] VM returned with error err="out of gas".
0

DEBUG[06-25|19:34:00|core/state_transition.go:216] VM returned with error err="out of gas".

This means the gas you provided is not adequate enough to get your contract operation done. Are you sure your transaction to set the value actually succeed? You can check this in the Remix IDE receipt log of the transaction. I guess it might have failed due to not enough gas (out of gas error) and hence val in your Referred contract is always zero.

Raise the gas to sufficient amount. Try with 4700000 for example. You can see gas used in the receipt log in Remix IDE so that you can use that gas amount to be more precise.


Based on your comment below I have made this edit. I have run this contract successfully in Remix IDE. I suspect you are not executing the contract operation properly. Note that, you should first call function deployOther() after deploying both the contracts. The link between Test and Referred contract is made in this deployOther function. You should use the address of Referred contract in the place of 123.

1) First deploy Referred Contract.

2) Now change the address of the Referred contract in deployOther function. And deploy the Test contract

3) Now call the deployOther function.

4) Perform the set operation.

You have hard coded the address of Referred contract here, I suggest to send this address as parameter in deployOther function.

  • I have udpated with correct code. Also, tried increasing as mentioned, but no luck, same error. I tried the same contract with Parity; getting 0 there too. So, i think there is some basic stuff missing – karts Jun 26 '18 at 3:22
  • did you try by connecting to a private network? It works for me also if I choose 'JavaScript VM' in remix. But, when i connect to a private node i always get 0 – karts Jun 26 '18 at 6:22
  • have you tried any other contracts in your private network? do they work? – biplavo Jun 26 '18 at 7:22
  • yes, contracts work...only this scenario is not working for me – karts Jun 26 '18 at 13:06
0

I put your code into Remix and it works perfectly fine for me.

transact to Test.get pending ...

transaction cost    23745 gas    

decoded output  {
    "0": "uint256: 123"
}

and after transact to Test.set pending ... transact to Test.get pending ...

transaction cost    23745 gas

decoded output  {
    "0": "uint256: 456"
}
  • did you try by connecting to a private network? It works for me also if I choose 'JavaScript VM' in remix. But, when i connect to a private node i always get 0. – karts Jun 26 '18 at 6:21
0

Got it working after downgrading my geth node to 1.8.10 and using 0.4.21 solidity. Also, added the following in the my genesis block config,

"homesteadBlock": 0, "eip150Block": 0, "eip155Block": 10, "eip158Block": 10, "eip160Block": 10, "byzantiumBlock": 10,

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.