Skip to content
Verified contractExactMIT

ETHAutoForwarder

Address0x596a33695ff82b2c58f68e816f14dc6ec6586b99
Balance

0 ETH

 

Transactions

3

 

Compiler

solc 0.8.19

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.19+commit.7dd6d404
Language
solidity
Optimization
No
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,585,080
Creation transaction
0xc05c82dd2c…e7788e7a6a

autosend.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

/**
 * @title ETH Auto Forwarder
 * @dev Automatically forwards any ETH received to: 0x403a5dDa82b2A62d6e5B89dFCD6e82Cd15d8dae7
 */
contract ETHAutoForwarder {
    // Your target address - hardcoded for automatic forwarding
    address payable public constant TARGET_ADDRESS = payable(0x403a5dDa82b2A62d6e5B89dFCD6e82Cd15d8dae7);
    
    // Owner for administrative functions
    address public owner;
    
    // Events for tracking
    event FundsForwarded(uint256 amount, uint256 gasUsed, uint256 gasCost, uint256 timestamp);
    event Received(address indexed from, uint256 amount);
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    
    /**
     * @dev Constructor sets the owner
     */
    constructor() {
        owner = msg.sender;
    }
    
    /**
     * @dev Receive ETH and auto-forward to target address
     */
    receive() external payable {
        emit Received(msg.sender, msg.value);
        _forwardFunds();
    }
    
    /**
     * @dev Fallback function for ETH transfers with data
     */
    fallback() external payable {
        emit Received(msg.sender, msg.value);
        _forwardFunds();
    }
    
    /**
     * @dev Internal function to forward all ETH with gas calculation
     */
    function _forwardFunds() internal {
        uint256 contractBalance = address(this).balance;
        
        if (contractBalance > 0) {
            // Record gas before transfer
            uint256 gasStart = gasleft();
            
            // Forward all ETH to your address
            (bool success, ) = TARGET_ADDRESS.call{value: contractBalance, gas: 30000}("");
            
            if (success) {
                // Calculate gas used and cost
                uint256 gasUsed = gasStart - gasleft();
                uint256 gasCost = gasUsed * tx.gasprice;
                
                emit FundsForwarded(contractBalance, gasUsed, gasCost, block.timestamp);
            }
        }
    }
    
    /**
     * @dev Manual trigger to forward any accumulated ETH
     */
    function forwardFunds() external {
        _forwardFunds();
    }
    
    /**
     * @dev Owner can manually forward with custom gas limit
     */
    function manualForward(uint256 gasLimit) external onlyOwner {
        uint256 contractBalance = address(this).balance;
        require(contractBalance > 0, "No funds to forward");
        require(gasLimit > 0, "Gas limit must be > 0");
        
        uint256 gasStart = gasleft();
        
        (bool success, ) = TARGET_ADDRESS.call{value: contractBalance, gas: gasLimit}("");
        require(success, "Forward failed");
        
        uint256 gasUsed = gasStart - gasleft();
        uint256 gasCost = gasUsed * tx.gasprice;
        
        emit FundsForwarded(contractBalance, gasUsed, gasCost, block.timestamp);
    }
    
    /**
     * @dev Check contract balance
     */
    function getBalance() external view returns (uint256) {
        return address(this).balance;
    }
    
    /**
     * @dev Get current gas price
     */
    function getGasPrice() external view returns (uint256) {
        return tx.gasprice;
    }
    
    /**
     * @dev Transfer ownership
     */
    function transferOwnership(address newOwner) external onlyOwner {
        require(newOwner != address(0), "Invalid address");
        address oldOwner = owner;
        owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
    
    /**
     * @dev Withdraw function in case of emergency (owner only)
     */
    function emergencyWithdraw() external onlyOwner {
        uint256 balance = address(this).balance;
        require(balance > 0, "No balance");
        (bool success, ) = TARGET_ADDRESS.call{value: balance}("");
        require(success, "Withdraw failed");
    }
    
    // Modifiers
    modifier onlyOwner() {
        require(msg.sender == owner, "Only owner can call");
        _;
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.