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.

2 Answers 2

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

0

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.