ERROR send 和 transfer 仅适用于 address payable 类型的对象,不适用于 address

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

错误行---> request.recipient.transfer(request.value);

有人可以帮我解决这个问题吗?谢谢。

我正在使用的 solidity 版本:

pragma solidity >0.4.17 <0.8.0;

您需要将 request.recipient 标记为 payable

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

如果您使用的编译器早于 0.6,您可以将 recipient 声明为 address payable 而不是 address。 如果你使用的编译器大于或等于 0.6,你可以使用@Petr Hejda 提供的解决方案。

代码中没有错误,它很好,但在执行时我传递了地址,然后我得到如下 Remix 中给出的错误 ide

:status false 交易已开采但执行失败” 交易至 transferEther.payBill 错误:虚拟机错误:还原。

还原 事务已恢复到初始状态。 注意:如果您发送价值,并且您发送的价值应小于您的当前余额,则调用的函数应该是可支付的。 调试交易以获取更多信息。