Greeter

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);
    }
}

Tags:
addr:0xf870cb8ae095a164d15b93c0d4ae6e88158d04b9|verified:true|block:23559446|tx:0x02e7f1d6d04eb55a2f1f68b2a3663400a6f1dbc202aefb547cf194e9d7001e28|first_check:1760288720

Submitted on: 2025-10-12 19:05:23

Comments

Log in to comment.

No comments yet.