ERROR send and transfer are only available for objects of type address payable, not address [solidity]

Solidity Error - send and transfer are only available for objects of type address payable not address

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 .transfer() and .send() on type Address. These function calls are available for Address Payable and not Address.

Introduction

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 .transfer() and .send() but you cannot do this on simple address. In other words, address payable can receive Ether but address can not.

Solution

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));

Or

address simpleAddr = msg.sender;
address payable addrPay1 = address(simpleAddr);

      Solving Solidity Error: Send and Transfer only available for address payable ♥♥

Click here to Tweet this

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:

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.

Conclusion

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.