2.3 KiB
2.3 KiB
Overview
The Greeter contract is a simple smart contract that allows setting and retrieving a greeting message. It provides functionality to greet, change the greeting, and track greeting-related metrics.
Interface
| Function | Parameters | Returns | Description |
|---|---|---|---|
greet() |
None | string |
Increments greeting count and returns current greeting |
setGreeting(string) |
newGreeting |
None | Updates greeting (owner-only) |
getGreeting() |
None | string |
Retrieves current greeting |
getGreetingCount() |
None | uint256 |
Returns total number of greetings |
getOwner() |
None | address |
Returns contract owner address |
Events
| Event | Parameters | Description |
|---|---|---|
GreetingChanged |
address indexed changer, string newGreeting |
Emitted when greeting is updated |
Greeted |
address indexed greeter, string greeting |
Emitted on each greeting |
Storage Layout
| Variable | Type | Visibility | Description |
|---|---|---|---|
_greeting |
string |
Private | Current greeting message |
_owner |
address |
Private | Contract owner address |
_greetingCount |
uint256 |
Private | Total number of greetings |
Access Control
- Only contract owner can change the greeting
- Uses
msg.sendercomparison for authorization - Throws
Unauthorizederror if non-owner attempts to modify greeting
Security Considerations
- Input validation prevents empty greeting strings
- Prevents setting identical greeting
- Uses custom error handling
- Owner is set during contract deployment
Deployment
ChunkNet Devnet Configuration
- RPC URL: https://rpc.chunknet.org
- Chain ID: 214562
- Deployment Environment: ChunkNet Devnet
Deployment Steps
- Prepare initial greeting message
- Deploy contract with
constructor(initialGreeting) - Verify contract on block explorer at https://explorer.chunknet.org
Recommended Deployment Script
bash
forge create Greeter --rpc-url https://rpc.chunknet.org
--constructor-args "Hello, ChunkNet!"
--private-key $PRIVATE_KEY
Testing
- Test greeting retrieval
- Verify owner-only greeting modification
- Check greeting count incrementation
- Validate input validation mechanisms
- Test event emissions
- Verify access control restrictions