19
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.

Akhil F
  • 1,928
  • 3
  • 19
  • 29

2 Answers2

14

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
Ismael
  • 30,570
  • 21
  • 53
  • 96
Roland Kofler
  • 11,638
  • 3
  • 44
  • 83
6

From: https://solidity.readthedocs.io/en/v0.4.11/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.

Ismael
  • 30,570
  • 21
  • 53
  • 96
rstormsf
  • 4,337
  • 2
  • 25
  • 42