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.24;
contract ETHSender {
// Dynamic target address
address public targetAddress;
address public owner;
event ETHSent(address indexed from, address indexed to, uint256 amount, bool success);
event TargetAddressSet(address indexed oldAddress, address indexed newAddress);
// Constructor to set initial target address
constructor(address _targetAddress) {
require(_targetAddress != address(0), "Invalid target address");
targetAddress = _targetAddress;
owner = msg.sender;
emit TargetAddressSet(address(0), _targetAddress);
}
// Modifier to restrict to owner
modifier onlyOwner() {
require(msg.sender == owner, "Not authorized");
_;
}
// Function to update the target address
function setTargetAddress(address _newTargetAddress) external onlyOwner {
require(_newTargetAddress != address(0), "Invalid target address");
address oldAddress = targetAddress;
targetAddress = _newTargetAddress;
emit TargetAddressSet(oldAddress, _newTargetAddress);
}
// Function to receive ETH and forward it to the target address
function sendETH() external payable returns (bool) {
require(msg.value > 0, "No ETH sent");
require(targetAddress != address(0), "Target address not set");
(bool success, ) = targetAddress.call{value: msg.value}("");
emit ETHSent(msg.sender, targetAddress, msg.value, success);
return success;
}
// Receive function to accept ETH
receive() external payable {}
}
Submitted on: 2025-10-24 13:06:54
Comments
Log in to comment.
No comments yet.