以下是合约代码 function currencyTransfer(address payable recipient, uint256 amount) external { require(msg.sender == owner, "Only owner can call this function"); recipient.transfer(amount); }
如果合约中有eth,并且recipient地址可以接收eth,在做好权限检查后,可以进行eth转账。但不推荐使用transfer,推荐使用call。
function currencyTransfer(address payable recipient, uint256 amount) external {
require(msg.sender == owner, "Only owner can call this function");
(bool success, bytes memory err) = recipient.call{value: amount}("");
require(success, err);
}