2.9 KiB
2.9 KiB
Overview
GreeterFactory is a Solidity smart contract designed to manage the creation and destruction of Greeter contract instances. It provides a factory pattern for deploying multiple Greeter contracts with unique initial greetings, allowing users to create, track, and destroy their own Greeter instances.
Interface
| Function | Visibility | Parameters | Returns | Description |
|---|---|---|---|---|
createGreeter |
Public | string initialGreeting |
address |
Creates a new Greeter contract with the specified initial greeting |
destroyGreeter |
Public | address greeterAddress |
void |
Destroys a specific Greeter contract owned by the caller |
getOwnerGreeterInstances |
Public View | address owner |
address[] |
Retrieves all Greeter instances owned by a specific address |
isActiveGreeter |
Public View | address greeterAddress |
bool |
Checks if a Greeter contract is currently active |
Events
-
GreeterCreated(address indexed greeter, address indexed owner, string initialGreeting)- Emitted when a new Greeter contract is created
- Provides the new contract address, owner, and initial greeting
-
GreeterDestroyed(address indexed greeter, address indexed owner)- Emitted when a Greeter contract is destroyed
- Provides the destroyed contract address and owner
Storage Layout
_ownerGreeterInstances: Mapping tracking Greeter instances per owner_activeGreeterInstances: Mapping tracking active Greeter contract addresses- Stores references to created Greeter contracts for management and tracking
Access Control
createGreeter(): Permissionless, any address can create a GreeterdestroyGreeter(): Restricted to the original Greeter contract owner- View functions are publicly accessible
Security Considerations
- Input validation for non-empty greetings
- Owner-only destruction mechanism
- Prevents duplicate or invalid contract interactions
- Uses
deleteand array manipulation for instance tracking
Deployment
ChunkNet Devnet Deployment
- RPC URL: https://rpc.chunknet.org
- Chain ID: 214562
- Recommended Deployment Steps:
- Ensure sufficient gas funds
- Use ChunkNet RPC URL for deployment
- Set appropriate gas limits and priorities
- Verify contract post-deployment
Recommended Deployment Script
bash
forge create GreeterFactory
--rpc-url https://rpc.chunknet.org
--private-key $PRIVATE_KEY
Testing
Test Coverage
- Contract creation with valid greeting
- Contract creation with empty greeting (should revert)
- Destroying owned Greeter contracts
- Preventing unauthorized contract destruction
- Tracking owner's Greeter instances
- Verifying active/inactive contract states
Test Scenarios
- Create multiple Greeter instances
- Verify ownership tracking
- Attempt unauthorized contract destruction
- Validate instance management functions