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;
contract Greeter {
string private greeting;
address public owner;
uint256 public totalGreetings;
event GreetingChanged(string newGreeting, uint256 timestamp);
event GreetingSent(address indexed sender, string message, uint256 timestamp, uint256 chainId);
constructor() {
owner = msg.sender;
greeting = unicode"Good Morning! ☀️";
}
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
function setGreeting(string memory _newGreeting) external onlyOwner {
require(bytes(_newGreeting).length > 0, "Empty greeting");
greeting = _newGreeting;
emit GreetingChanged(_newGreeting, block.timestamp);
}
function getGreeting() external view returns (string memory) {
return greeting;
}
function sayGM() external {
totalGreetings++;
emit GreetingSent(msg.sender, greeting, block.timestamp, block.chainid);
}
function sayGM(string memory _customGreeting) external {
require(bytes(_customGreeting).length > 0, "Empty greeting");
totalGreetings++;
emit GreetingSent(msg.sender, _customGreeting, block.timestamp, block.chainid);
}
function transferOwnership(address _newOwner) external onlyOwner {
require(_newOwner != address(0), "Invalid address");
owner = _newOwner;
}
function getChainId() external view returns (uint256) {
return block.chainid;
}
function getStats() external view returns (string memory currentGreeting, uint256 totalTxns, uint256 chainId) {
return (greeting, totalGreetings, block.chainid);
}
}
Submitted on: 2025-10-12 19:05:23
Comments
Log in to comment.
No comments yet.