Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

solidity

function finalizeRequest(uint index) public restricted {
    Request storage request = requests[index];
    
    require(request.approvalCount > (approversCount / 2));
    require(!request.complete);
    
    request.recipient.transfer(request.value);
    request.complete = true;
}

error line ---> request.recipient.transfer(request.value);

can someone help me with this? Thank you.

solidity version I'm using:

pragma solidity >0.4.17 <0.8.0;
like image 404
Juodas Baltas Avatar asked May 01 '21 00:05

Juodas Baltas


People also ask

What is address payable in solidity?

The distinction between address and address payable was introduced in Solidity version 0.5. 0. The idea was to make the distinction between addresses that can receive money, and those who can't (used for other purposes). Simply speaking, an address payable can receive Ether, while a plain address cannot.

What is payable function in solidity?

What is Payable in Solidity? When writing a smart contract, you need to ensure that money is being sent to the contract and out of the contract as well. Payable does this for you, any function in Solidity with the modifier Payable ensures that the function can send and receive Ether.


Video Answer


2 Answers

You need to mark the request.recipient as payable

payable(request.recipient).transfer(request.value);

From the docs page Solidity v0.8.0 Breaking Changes:

The global variables tx.origin and msg.sender have the type address instead of address payable. One can convert them into address payable by using an explicit conversion, i.e., payable(tx.origin) or payable(msg.sender).

like image 158
Petr Hejda Avatar answered Dec 02 '22 19:12

Petr Hejda


If you are using a complier older than 0.6, you can declare recipient as address payable instead of address. If you are using a compiler more or equal to 0.6, you can use the solution provided by @Petr Hejda.

like image 25
Abdulrazak Zakieh Avatar answered Dec 02 '22 20:12

Abdulrazak Zakieh