Juodas Baltas
Juodas Baltas

Reputation: 315

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

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;

Upvotes: 27

Views: 24172

Answers (3)

Petr Hejda
Petr Hejda

Reputation: 43481

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

Upvotes: 72

Pankaj Joshi
Pankaj Joshi

Reputation: 11

There is no error in code its fine but upon execution i passed address then i get Error as given below in Remix ide

:status false Transaction mined but execution failed" transact to transferEther.payBill errored: VM error: revert.

revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.

Upvotes: 1

Abdul Razak Zakieh
Abdul Razak Zakieh

Reputation: 764

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.

Upvotes: 8

Related Questions