1

I'm trying to make nested calls or whatever they are called. I always get out of gas exception. What am I missing?

From JS side I do caller.makeCall(firstAddress, secondAddress, {gas:300000, value: 300000000000000000}, callback)

Here are the contracts:

contract caller {
    function makeCall(address first, address second){
        first.call.gas(100000).value(200000000000000000)(bytes4(bytes32(sha3('makeCall(address)'))), second);
    }
}

contract first {
    function makeCall(address second) {
        second.call.gas(100000).value(100000000000000000)(bytes4(bytes32(sha3('make()'))));
    }
}

contract second {
    uint public x = 1;
    function make(){
        x = 2;
    }
    function(){
        x = 3;
    }
}

I've double checked everything. I've supplied up to 3 million gas and still get out of gas exception.

Here's a tx https://testnet.etherscan.io/tx/0xf5986e85f7601e6a896eda22d72cb302d59013f9750c9997bf112acea757f839

Please help!

1

You are changing the function parameters not the gas values. See the documentation for the correct syntax of calling external contract methods from contracts.

Never use call() for methods that change the state of the block chain. call() is used only to query (read) the block chain.

0

Whew, I've found a bug.

So, the problem was that first.call.gas(100000) forwards to contract first exactly this amount. When EVM control reaches second.call.gas(100000) it forwards this amount to contract second and as a result there's no more gas left for contract first. And that's where out of gas exception comes from. Now, I've changed first.call.gas(100000) to first.call.gas(200000) and everything works just fine.

  • caller has 0.1 ether balance
  • first has 0.1 ether balance
  • second has 0.1 ether balance
  • uint public x == 2

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.