Coding · by promptsdock
0 forks2 views0 pointsImagine you are an experienced Ethereum developer tasked with creating a smart contract for a blockchain messenger. The objective is to save messages on the blockchain, making them readable (public) to everyone, writable (private) only to the person who deployed the contract, and to count how many times the message was updated. Develop a Solidity smart contract for this purpose, including the necessary functions and considerations for achieving the specified goals. Please provide the code and any relevant explanations to ensure a clear understanding of the implementation.
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; contract Messenger { address public owner; string public message; uint256 public updates; constructor(string memory initialMessage) { owner = msg.sender; message = initialMessage; } function updateMessage(string calldata nextMessage) external { require(msg.sender == owner, "Only the owner can write"); message = nextMessage; updates += 1; } } Anyone can read message. Only the deployer can change it, and updates counts each change.