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

3 Answers 3

72

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

3
  • That gives me: ParserError: Expected primary expression.payable(orders[i].investor).transfer(msg.value * orders[i].amount / totalRaised); ^-----^ Jul 24, 2021 at 6:49
  • @lampbottle This seems like a syntax error unrelated to this question. Please post a separate question with steps to reproduce your issue.
    – Petr Hejda
    Jul 24, 2021 at 10:55
  • It was because I was using an older version of solidity Jul 24, 2021 at 12:08
8

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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.