Building upon the concept of payable addresses, which enable contracts to receive Ether, this guide explores the essential Ether transfer methods in Solidity: transfer, send, and call. Understanding these methods is crucial for securely and effectively managing Ether transactions in smart contract development.

Objectives

After this lesson, you should be able to:

Ether Transfer Methods

Solidity provides three distinct methods for sending Ether from contracts, each with specific use cases and security considerations:

transfer

This method sends Ether directly and safely. If the transaction encounters any issues, it automatically reverses:

Specification:

<address payable>.transfer(uint256 amount)

Usage Example:

_to.transfer(msg.value); // Reverts on failure due to gas limit

send

Functionally similar to transfer, send differs in its response to errors. Instead of reverting automatically, it returns a boolean result indicating success or failure: