// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
contract EtherBox {
address public owner;
event LogMe(string message, address sender, uint amount);
constructor() {
owner = msg.sender; // Set the contract creator as the owner
}
// Fallback function to log incoming transactions with data
fallback() external payable {
emit LogMe("Fallback called", msg.sender, msg.value);
}
// Receive function to handle plain Ether transactions
receive() external payable {
emit LogMe("Receive called", msg.sender, msg.value);
}
// Function to withdraw Ether from the contract
function withdraw(uint _amount) external {
require(msg.sender == owner, "Only the owner can withdraw");
payable(owner).transfer(_amount);
}
// Function to check the balance of Ether in the contract
function getBalance() public view returns (uint) {
return address(this).balance;
}
// Function to change the owner of the contract
function changeOwner(address _newOwner) external {
require(msg.sender == owner, "Only the owner can change ownership");
owner = _newOwner;
}
}