Description:
Smart contract deployed on Ethereum.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/// @title ETHSwapForwarder
/// @notice Automatically forwards ETH sent by users to a fixed recipient
contract ETHSwapForwarder {
address public owner;
address public recipient;
event Forwarded(address indexed from, uint256 amount);
event RecipientUpdated(address indexed previous, address indexed current);
event OwnershipTransferred(address indexed previous, address indexed current);
modifier onlyOwner() {
require(msg.sender == owner, "Only owner");
_;
}
constructor(address _recipient) {
require(_recipient != address(0), "Invalid recipient");
owner = msg.sender;
recipient = _recipient;
emit OwnershipTransferred(address(0), owner);
}
/// @notice Automatically forwards any ETH sent to the contract
receive() external payable {
require(msg.value > 0, "No ETH sent");
(bool success, ) = payable(recipient).call{value: msg.value}("");
require(success, "ETH forward failed");
emit Forwarded(msg.sender, msg.value);
}
/// @notice Owner can update recipient
function updateRecipient(address newRecipient) external onlyOwner {
require(newRecipient != address(0), "Invalid recipient");
emit RecipientUpdated(recipient, newRecipient);
recipient = newRecipient;
}
/// @notice Transfer ownership
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "Invalid owner");
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
Submitted on: 2025-09-24 14:19:40
Comments
Log in to comment.
No comments yet.