As described in the solidity docs on the address type, a payable address can do everything an address can do, in addition to having access to the .transfer(...)
and .send(...)
functions. So you might declare a state variable as address payable
instead of just address
if you explicitly want to indicate that it's allowed to receive ether from the contract, and want to cast it once instead of every time you need to call those functions.
If owner
is a state variable that's declared as a payable address like address payable public owner;
, the solidity wouldn't compile if you attempt to directly assign an address like msg.sender
to it without casting it:
TypeError: Type address is not implicitly convertible to expected type address payable
But if owner
was declared as a basic address like address public owner;
you could just as easily cast the address to payable if and when you need it:
payable(owner).transfer(...);
Also, since .call{value: ...}('')
is currently the recommended way to send value instead of .transfer
and .send
and can be used with a plain address, there doesn't appear to be much value in marking an address as payable beyond perhaps for indicating intent for readability.
Note that this is a different concern from marking a function with the payable
modifier like function fund() external payable
, which makes it so that a function is allowed to receive ether from a user or another contract when it's called, which gets added to the balance of the contract and is visible under msg.value
.