0
contract Sample{

    event Data(uint test) ; 

    function test2() {
        Data(msg.gas) ;
    }
}


contract Sample2{
    function try(address addr){
       Sample(addr).test2() ;
       addr.call(bytes4(keccak256("test2()"))) ;
    }
}

How does the method call send gas? If all of remaining gas was sent to the target, when I use call or just Sample(address).test2()?

0

Gas is sent with signed transactions. It arrives at a function, say Sample2(addressSample2).try().

Since you did not specify an amount of gas with your call, all remaining gas is sent to Sample(addressSample).test2(). When it is finished, control returns to Sample2(addressSample2).try() along with any unspent/remaining gas. No gas remains in Sample(addressSample).

Since Sample2(addressSample2).try() is also done, the remaining gas returns to the sender. No surplus gas remains in either contract which is just as well, because cannot presently pay for their own gas.

Sample(address).test2() emits an event with the remaining gas at that moment, but processing will continue as described above. So, some additional gas will be burned before the transaction completes.

In case it isn't clear, there are assembly-level OPCODES that still need to run before everything will be wrapped up as summarized above. It's probably enough to know that there's still housekeeping to attend to because the function hasn't (technically) finished. If you're so inclined, you can step over the OPCODES in Remix to study what it does near the end.

Hope it helps.

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.