Table of Contents Hide
In Solidity, you may encounter this error, “send and transfer are only available for objects of type address payable, not address” when you try to run function calls like
.send() on type Address. These function calls are available for Address Payable and not Address.
Address and Address payable are both 160-bit Ethereum addresses but the difference between them exist on the compile-time. Address payable can use different calls such as
.send() but you cannot do this on simple address. In other words, address payable can receive Ether but address can not.
You can cast one of the type into the other type through different ways. You may choose whichever is suitable for you. Here I have provided two of those for both the types:
Casting address payable to address:
address payable addrPay = msg.sender; address simpleAddr = addrPay; address simpleAddr1 = address(addrPay);
Casting address to address payable:
address simpleAddr = msg.sender; address payable addrPay = address(uint160(simpleAddr));
address simpleAddr = msg.sender; address payable addrPay1 = address(simpleAddr);
Why we have different addresses?
The reason behind having different data types which are not too dissimilar from each other can vary from language to language but some of the most common reasons could be:
- To provide type specific functionalities. For example + sign is used to add numbers stored in two different variable of number data type but if we use the same + sign between two variable of string data type it will concatenate the two strings.
- For limiting the number of incorrect programs that are received by the compiler by being as specific as possible for different types of data even if the difference is too small.
In case of address and address payable the reason behind splitting the two different data types is second one. Because by doing so the coder who is writing the smart contract can decide weather they are looking for simple address or want to transfer ether in that address. If for whatever reason the coder make some mistake it can be notified at the compile time.
To solve Solidity error of “send and transfer are only available for objects of type address payable, not address” you just need to cast a simple address to address payable.