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.

Similar Reads

Basics of Addresses and Address Literals

The address type in Solidity is a 20-byte value that represents an Ethereum address. It can hold the address of a user or a contract on the Ethereum network. Here’s an example of declaring and using an address variable in Solidity:...

Address vs Address Payable

...

Methods Available with Addresses

...

Type Conversions between Addresses and 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:...

Methods Returning an Address Type

...