Address vs Address Payable
In Solidity, there are two address types: address and address payable. The address type is used for both user addresses and contract addresses, while the address payable type is specifically used for addresses that can receive Ether. Here’s an example:
Solidity
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; contract helloGeeks { address public userAddress; address payable public recipientAddress; function setAddress(address _userAddress, address payable _recipientAddress) public { userAddress = _userAddress; recipientAddress = _recipientAddress; } } |
Output
In this example, the userAddress variable is of type address, while the recipientAddress variable is of type address payable This difference allows the recipientAddress address to receive Ether.
Address in Solidity
In Solidity, the address type represents Ethereum addresses. Understanding how to work with addresses is essential for developing smart contracts that interact with users and other contracts on the Ethereum blockchain. This article aims to provide a comprehensive guide to addresses in Solidity, accompanied by relevant examples and covering various subtopics.