블록체인 메신저용 솔리디티 스마트 컨트랙트 로직과 코드를 한 번에 작성합니다.
Imagine 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.
당신이 블록체인 메신저용 스마트 컨트랙트를 제작하는 숙련된 이더리움 개발자라고 가정해 보세요. 목표는 블록체인에 메시지를 저장하여 누구나 읽을 수 있게(공개) 하고, 작성(수정)은 컨트랙트를 배포한 사람만 가능하게(비공개) 하며, 메시지가 업데이트된 횟수를 카운트하는 것입니다. 지정된 목표를 달성하기 위해 필요한 기능과 고려사항을 포함하여 이를 위한 Solidity 스마트 컨트랙트를 개발해 주세요. 구현 방식을 명확히 이해할 수 있도록 코드와 관련 설명을 함께 제공해 주세요.
출처 · prompts.chat · Ethereum Developer — 원문은 출처에 게시된 그대로이며, 권리는 원작자에게 있습니다.
Gemini로 실행한 결과입니다. 입력 항목에는 국내 환경의 예시값을 적용했습니다(AI 생성 — 사실 확인 필요).
Imagine 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.
요구사항을 충족하는 Solidity 스마트 컨트랙트 구현 예시입니다.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract BlockchainMessenger {
address public immutable owner;
string public message;
uint256 public updateCount;
event MessageUpdated(string newMessage, uint256 count);
modifier onlyOwner() {
require(msg.sender == owner, "Not authorized: Only owner can update");
_;
}
constructor(string memory initialMessage) {
owner = msg.sender;
message = initialMessage;
updateCount = 0;
}
function setMessage(string memory newMessage) public onlyOwner {
message = newMessage;
updateCount++;
emit MessageUpdated(newMessage, updateCount);
}
}핵심 설명
constructor에서 컨트랙트를 배포한 계정(msg.sender)을 owner로 설정합니다. immutable 키워드로 변조를 방지합니다.message와 updateCount를 public으로 선언하여 누구나 블록체인에서 비용(Gas) 없이 조회할 수 있습니다.setMessage 함수에 onlyOwner 커스텀 modifier를 적용해 배포자만 메시지를 수정할 수 있도록 제한합니다.setMessage가 호출될 때마다 updateCount를 1씩 증가시키고 이벤트를 알립니다.mopick 개선안
원문을 그대로 넣으면 AI 가 매번 다르게 답하거나 중요한 부분을 빠뜨릴 수 있습니다. 개선안은 원문의 뜻과 언어는 그대로 두고 역할 · 바꿔 넣을 입력 칸 · 결과 형식 · 지킬 조건을 보완해 다시 쓴 버전입니다. 원문과 같은 곳(ChatGPT · Claude 등)에 그대로 붙여 넣어 쓰면 됩니다.
AI 자체 평가 — 개선안을 쓴 AI 가 명확성 · 구체성 · 결과 형식 · 재사용성 기준(100점)으로 직접 매긴 점수 · 결과를 돌려 검증한 값은 아님
AI 역할레슨 01 배우기 ›
원문 · 없음AI 에게 맡길 역할이 정해져 있지 않아 답의 관점 · 수준이 그때그때 달라질 수 있었습니다.
개선 · 역할을 정함Act as a senior Ethereum developer. Write a production-ready Solidity ([e.g., ^0.8.20]) sm
입력 칸레슨 05 배우기 ›
원문 · 없음바꿔 넣을 자리가 표시돼 있지 않아 쓸 때마다 원문을 직접 고쳐야 했습니다.
개선 · 1개[e.g., ^0.8.20]
작업 순서레슨 07 배우기 ›
원문 · 없음작업 순서가 정해져 있지 않아 AI 가 순서를 스스로 정해야 했습니다.
개선 · 5단계
이 개선안에 쓰인 기법 — 프롬프트 클래스에서 배우기
01역할 정하기03결과 모양 정하기04지킬 조건 걸기05입력 칸으로 템플릿 만들기07작업을 단계로 나누기09구역을 나눠 쓰기
원문
Imagine 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.
개선안 · 색칠한 [칸]에 내 내용을 넣어 쓰세요
Act as a senior Ethereum developer. Write a production-ready Solidity ([e.g., ^0.8.20]) smart contract for a blockchain messenger based on these specifications: ### Requirements: 1. State Management: Store a publicly readable message and track the total update count. 2. Access Control: Only the contract deployer (owner) can modify the message. 3. Event Logging: Emit an event whenever the message is updated. ### Constraints & Best Practices: - Use custom errors or modifiers for access restriction. - Add NatSpec comments for clarity. ### Output Format: 1. **Solidity Smart Contract**: Complete, compilable code block including SPDX license and pragma statement. 2. **Technical Breakdown**: Explanation of state variables, access control implementation, and event structure.