Solidity 0.6.4 and call{value: ...}() instead of call.value()()

Solidity 0.6.4 deprecated something which almost slipped my attention. address.call.value()() was deprecated and got replaced with address.call{value: x}(). Let's check out how this works.

When I saw the syntax the first time - when a student asked me in our course Q&A about this - I was admittedly a bit confused.

The student wrote it like this:

someAddress.call({value: 1 **ether**})(abi.encodeWithSignature("someFunction(uint256)", _arg1))

That doesn't work. Because the new syntax is without round brackets around the curly brackets. Essentially like this:

someAddress.call{gas: x, value: y}(data)

the order of value and gas does not matter according to the Solidity Docs.

Let's take this contract example where the contract calls itself (just for simplicity sake):

pragma solidity ^0.6.6;

contract MyContract {
    function someFun() public {
        (bool success,  ) = address(this).call{value: 1 ether}(abi.encodeWithSignature("someOtherFunction(uint256)", 123));
        require(success, "Contract execution Failed");
    }
    
    function someOtherFunction(uint _myVar) public {
        //do something
    }
}

And then let's consider another example where we actually do something with an external address for a pull withdraw function:

pragma solidity ^0.6.6;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol";

contract MyContract {
    
    using SafeMath for uint;
    mapping(address => uint) public someBalance;
    
    function withdrawFunds(uint _amount, address payable _to) public {
        require(someBalance[msg.sender] >= _amount, "You don't have enough funds. Aborting!");
        someBalance[msg.sender] = someBalance[msg.sender].sub(_amount);
        (bool success,  ) = _to.call{value: _amount}("");
        require(success, "Failed to transfer the funds, aborting.");
    }
    
    receive() external payable {
        someBalance[msg.sender] = someBalance[msg.sender].add(msg.value);
    }
}

You could deploy that smart contract with Remix in the JavaScript VM: Then send 1 Ether to the Smart Contract from the current address: And hit the transact button at the end of the contract interaction box: This way a transaction is sent without any msg.data triggering the receive fallback function.

Now you can check how much money your address has in its balance. Copy the address and paste it into the someBalance Field:  It should say 1 Ether in Wei (10^18) Now lets transfer the 1 Ether to another address:

Select the Second address in the Accounts dropdown and copy it: Then re-select the first address in the account. Paste the amount to withdraw (100000000000000) and the address in the withdrawFunds fiel, separated with a comma, like so:

1000000000000000000,0xeedf8630D0aC0f278Ea630b3662d2d3df1d8F46A

Hit the Button to withdrawFunds: Observe that the second account has now 101 Ether. The transfer worked. If you are interested in a thorough and updated Solidity Masterclass, then check out the following course which is suitable for absolute Ethereum and Solidity beginners: [

Ethereum Blockchain Developer Bootcamp With Solidity (2020)

<p><strong>**</strong>Updated March 2020: New Full Project - Asset Tokenisation Using Open-Zeppelin ERC-20 Smart Contracts, Truffle 5, Solidity 0.6, MetaMask & React<strong>**</strong></p><p>Welcome to the <strong>Complete Ethereum Blockchain Development Bootcamp With Solidity</strong> - created by …

Udemy

](https://www.udemy.com/course/blockchain-developer/)