Msg.sender.call{} instead of msg.sender.send

Quick question,

In Filiip’s quick lesson on why we use .call instead of .send (to prevent your contract from not working in the future if updates to Solidity change the gas cost of certain operations)

the code he used was:

(bool success, ) = msg.sender.call{value: toTransfer}{"");

in regards to the {value: toTransfer} --> do you literally use the word “value” or is this where you place the actual integer amount…?

In other words, can someone write the psuedocode of the {value: toTransfer} part? is the outline {value (aka amount): variable}… I’m confused… what’s another example that you could enter in these brackets?

Hi @William

in regards to the {value: toTransfer} --> do you literally use the word “value” or is this where you place the actual integer amount…?

You have to write ‘value’ AND the amount.
The amount can be any integer value that you want the user to withdraw (in my example below I am using the contract balance).

pragma solidity 0.8.0;

contract Test {
    
    
    function deposit () public payable {}
    
    function withdraw () public returns (bool success) {
        ( success, ) = msg.sender.call{value: address(this).balance}("");
        if(success) return success;
    }
}