Objectives
By the end of this lesson, you should be able to:- Differentiate between address and address payable types in Solidity
- Determine when to use each type appropriately in contract development
- Employ address payable to send Ether and interact with payable functions
Ethereum Addresses
In Solidity, Ethereum addresses play a crucial role in interacting with the Ethereum blockchain. An Ethereum address is a 20-byte hexadecimal string that represents the destination of transactions or the owner of a smart contract. These addresses are used to send and receive Ether and interact with smart contracts.Addresses
Regular addresses in Solidity are used for various purposes, including:- Identifying the owner of a smart contract
- Sending Ether from one address to another
- Checking the balance of an address Here’s an example of declaring a regular address variable in Solidity:
Payable Addresses
payable
keyword is a language-level feature provided by Solidity to enable the handling of Ether within smart contracts, and it is not a feature of the Ethereum Virtual Machine itself, but rather a part of the Solidity language’s syntax. They are used when you want a contract to be able to receive Ether from external sources, such as other contracts or user accounts.
Payable addresses are often used when creating crowdfunding or token sale contracts, where users send Ether to the contract’s address in exchange for tokens or to fund a project.
Here’s an example of declaring a payable address variable in Solidity: