UnwrapAndForward

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

Tags:
Factory|addr:0xbf6fa3f58113139e7437da5dcce1cb005da387f3|verified:true|block:23590221|tx:0xce8269b502dc81ed1ef45c34412514e38bd9f498d4a7b5db5f72d403e6938c0c|first_check:1760621290

Submitted on: 2025-10-16 15:28:13

Comments

Log in to comment.

No comments yet.