ETH Price: $1,955.56 (-1.61%)

Contract Diff Checker

Contract Name:
EthRecoveryHelper

Contract Source Code:

File 1 of 1 : EthRecoveryHelper

// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

contract EthRecoveryHelper {
    address payable public originalContract;
    address payable public recipient;
    address private owner;

    constructor(address payable _originalContract, address payable _recipient) {
        originalContract = _originalContract;
        recipient = _recipient;
        owner = msg.sender;
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "Not owner");
        _;
    }

    // Improved recoverETH with error handling
    function recoverETH() external onlyOwner returns (bool success) {
        uint256 amount = address(originalContract).balance;
        require(amount > 0, "No ETH to recover");

        (success, ) = recipient.call{value: amount}("");
        require(success, "ETH transfer failed - recipient may reject payments");
        return success;
    }

    // Fallback: selfdestruct (use only if recoverETH fails)
    function recoverViaSelfDestruct() external onlyOwner {
        selfdestruct(recipient);
    }

    receive() external payable {}
}

Please enter a contract address above to load the contract details and source code.

Context size (optional):