// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; /// @title MessageContract /// @notice The smallest contract that is still interesting: it remembers a /// message, lets anyone change it, and announces every change. /// /// This is the contract you deploy in "Your First Contract" at /// https://litvm-academy.pro/build/your-first-contract contract MessageContract { /// @notice The current message. /// @dev Marking it `public` makes Solidity generate a `message()` getter /// for free, which is what the outside world will call to read it. string public message; /// @notice Who wrote the current message. address public author; /// @notice How many times the message has been changed. uint256 public changeCount; /// @notice Emitted on every change. /// @dev Events are the cheap way for a contract to tell the outside world /// that something happened. `indexed` lets anyone filter the log by /// author without reading every event ever emitted. event MessageChanged(address indexed author, string message, uint256 changeCount); /// @dev Runs once, at deployment, and is never callable again. Whatever it /// writes becomes the contract's starting state. constructor(string memory initialMessage) { message = initialMessage; author = msg.sender; changeCount = 0; } /// @notice Replace the message. /// @dev `msg.sender` is whoever sent the transaction. The chain proves it, /// so a contract never has to ask who is calling. function setMessage(string calldata newMessage) external { message = newMessage; author = msg.sender; changeCount += 1; emit MessageChanged(msg.sender, newMessage, changeCount); } /// @notice Read the message and who wrote it in one call. /// @dev `view` promises this changes nothing, so calling it costs no gas /// when you are only reading. function read() external view returns (string memory, address) { return (message, author); } }