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;
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 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.
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
andmsg.sender
have the typeaddress
instead ofaddress payable
. One can convert them intoaddress payable
by using an explicit conversion, i.e.,payable(tx.origin)
orpayable(msg.sender)
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With