Solidity — transfer vs send vs call function

Zuhaib Mohammed
Coinmonks
Published in
2 min readDec 31, 2021

--

In Solidity, there are three ways in which one can send ether. Namely transfer(), send() and call(). In this article, let us discuss how each function call works and which is the best one to use.

transfer vs send vs call

  1. transfer -> the receiving smart contract should have a fallback function defined or else the transfer call will throw an error. There is a gas limit of 2300 gas, which is enough to complete the transfer operation. It is hardcoded to prevent reentrancy attacks.
transfer() function

2. send -> It works in a similar way as to transfer call and has a gas limit of 2300 gas as well. It returns the status as a boolean.

send() function

3. call ->It is the recommended way of sending ETH to a smart contract. The empty argument triggers the fallback function of the receiving address.

(bool sent,memory data) = _to.call{value: msg.value}("");

using call, one can also trigger other functions defined in the contract and send a fixed amount of gas to execute the function. The transaction status is sent as a boolean and the return value is sent in the data variable.

(bool sent, bytes memory data) = _to.call{gas :10000, value: msg.value}("func_signature(uint256 args)");
call() function

Hope this article helped in understating the transfer, send and call functions.

Thanks for Reading!

Join Coinmonks Telegram Channel and Youtube Channel get daily Crypto News

Also, Read

--

--