Description:
Smart contract deployed on Ethereum with Factory features.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IWETH {
function withdraw(uint256 wad) external;
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
contract UnwrapAndForward {
/// @notice Canonical WETH for this deployment
IWETH public immutable WETH;
constructor(address weth) {
require(weth != address(0), "weth=0");
WETH = IWETH(weth);
}
/// @notice Unwrap WETH and forward ETH to recipient
/// @param amount Amount of WETH to pull/unwrap
/// @param recipient Receiver of the ETH
function unwrapAndSend(uint256 amount, address payable recipient) external {
// pull WETH from caller (caller must approve first)
bool ok = WETH.transferFrom(msg.sender, address(this), amount);
require(ok, "transferFrom failed");
// convert WETH -> ETH (ETH will be in this contract)
WETH.withdraw(amount);
// forward ETH to recipient
(bool sent, ) = recipient.call{value: amount}("");
require(sent, "ETH send failed");
}
// receive ETH from WETH.withdraw
receive() external payable {}
}
Submitted on: 2025-10-16 15:28:13
Comments
Log in to comment.
No comments yet.