4

If I send ether from contractB to contractA, then get error "out of gas".

Increase the amount of gas does not help.

In "VM Trace Transaction" http://testnet.etherscan.io/vmtrace?txhash=0x24269877942122ea5e022833e2dbd80f543458be2195ad2df222387cff7f5382 I see, then call "contractA.send(msg.value);" don't send gas to subcontract.

How to make these contracts work?

contract contractA {
    function() {
        for(uint i = 0;i<10; ++i)
            msg.sender.send(msg.value/10);
    }
}

contract contractB
{
    address contractA = 0x2EA16ad451ca2aA32E06f476691D1529cF11BaC7; // TestNet!!!
    function() {
        if (msg.sender != contractA) {
            contractA.send(msg.value);
        }
    }
}

1 Answer 1

4

You need to add gas to the transaction by calling msg.sender.call.gas(10000).value(msg.value/10)().

Be Careful: this could be vulnerable to recursive call attacks. In your case it isn't, but just be aware when sending gas to unknown contracts.

4
  • Where can I read the documentation for this command? Maybe contractA.call.gas(10000).value(msg.value)?
    – SkyN
    Jun 24, 2016 at 15:45
  • And yes, for the call to contractA that would be correct, except you're missing the parentheses at the end. Jun 24, 2016 at 15:48
  • call returns a boolean :)
    – SkyN
    Jun 24, 2016 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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