14
contract Test {

    function Test(){
        msg.sender.call.value(0);
        msg.sender.call.value(0)();
    }

}

Whats the difference here between the first and second call? My hunch is the 1st one doesn't actually do anything, however this indeed does compile.

10

The first should not do anything because the call function is not invoked. You just set the value that you want to send with the call but then don't invoke it. It is explained here:

Every external function call in Solidity can be modified in two ways:

  1. You can add Ether together with the call
  2. You can limit the amount of gas available to the call
3

From: https://solidity.readthedocs.io/en/latest/frequently-asked-questions.html#what-does-p-recipient-call-value-p-amount-p-data-do

What does p.recipient.call.value(p.amount)(p.data) do? Every external function call in Solidity can be modified in two ways:

You can add Ether together with the call You can limit the amount of gas available to the call This is done by “calling a function on the function”:

f.gas(2).value(20)() calls the modified function f and thereby sending 20 Wei and limiting the gas to 2 (so this function call will most likely go out of gas and return your 20 Wei).

In the above example, the low-level function call is used to invoke another contract with p.data as payload and p.amount Wei is sent with that call.

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.