This document summarizes the complete Ethereum deployment setup for AjoFactory to Sepolia testnet. All files have been created and configured following Ethereum and Hardhat best practices.
- Full-featured Ajo (Rotating Savings) factory contract
- Circle creation and management
- Member participation and contributions
- Platform fee management
- Emergency functions
- Comprehensive event logging
Key Features:
- Create circles with custom parameters
- Join existing circles
- Contribute to circles
- Query circle and membership information
- Platform owner controls
- Sepolia testnet network configuration
- Ethers.js v6 setup
- Gas reporting enabled
- Contract verification for Etherscan
- Environment variable security
Supported Networks:
sepolia- Main testnet for deploymenthardhat- Local testinglocalhost- Local node
Production-ready deployment with:
✅ Pre-flight Checks
- Validates deployer account exists
- Checks wallet balance (warns if < 0.1 ETH)
- Verifies network configuration
- Tests RPC connectivity
✅ Smart Error Handling
- Detects already-deployed contracts
- Prevents gas waste on retries
- Clear error messages
- Graceful failure handling
✅ Contract Deployment
- Deploys AjoFactory contract
- Waits for confirmation
- Logs deployment transaction details
✅ Automatic Verification
- Submits to Etherscan
- Waits for contract indexing
- Provides verification link
- Handles already-verified contracts
✅ Frontend Integration
- Saves contract ABI to JSON
- Exports deployment address
- Creates directly-importable config
- No manual copy-pasting required
✅ Comprehensive Logging
- Transaction hash
- Contract address
- Block number
- Gas usage
- Deployment timestamp
Comprehensive test coverage:
- Contract deployment validation
- Circle creation tests
- Member participation tests
- Contribution handling
- Permission and access control
- Platform management functions
Run tests:
pnpm contract:test # Run all tests
pnpm contract:test:gas # With gas reporting- Sepolia RPC configuration
- Private key management via .env
- Gas reporter setup
- Etherscan API integration
- Optimizer settings# Updated with Sepolia configuration
SEPOLIA_RPC_URL=...
SEPOLIA_PRIVATE_KEY=...
ETHERSCAN_API_KEY=..."contract:compile": "hardhat compile",
"contract:deploy:sepolia": "hardhat run scripts/deploy.ts --network sepolia",
"contract:deploy:local": "hardhat run scripts/deploy.ts --network hardhat",
"contract:test": "hardhat test",
"contract:test:gas": "REPORT_GAS=true hardhat test",
"contract:verify": "hardhat verify",
"contract:accounts": "hardhat accounts --network sepolia",
"contract:clean": "hardhat clean",
"hardhat:node": "hardhat node"Check deployment status and contract verification:
npx hardhat run scripts/check-deployment.ts --network sepoliaShows:
- Deployment records
- Contract verification status
- Frontend artifacts
- Explorer links
- Account balance
Helper functions for:
- Network configuration
- Address formatting
- Gas estimation
- Testnet validation
- Report generation
- Prerequisites and setup
- Environment configuration
- Step-by-step deployment
- Verification procedures
- Troubleshooting guide
- Security best practices
Sections:
- Prerequisites
- Setup steps
- Configuration details
- Deployment walkthrough
- Verification methods
- Post-deployment tasks
- Advanced usage
- Troubleshooting
- Quick start commands
- Available npm scripts
- Common operations
- Troubleshooting table
- Network details
- Integration checklist
- Setup instructions
- React hook examples
- Component implementations
- Read-only operations
- Event listening
- Error handling
- Gas estimation
Includes examples for:
- Creating circles
- Joining circles
- Contributing to circles
- Reading circle data
- User circle queries
- Real-time event listening
project/
├── contracts/
│ └── ethereum/
│ └── AjoFactory.sol # Main smart contract
├── scripts/
│ ├── deploy.ts # Deployment script ⭐
│ └── check-deployment.ts # Status checker
├── test/
│ └── AjoFactory.test.ts # Unit tests
├── lib/
│ ├── deployment-utils.ts # Helper utilities
│ └── [other libs]
├── frontend/
│ └── constants/
│ └── deployments/
│ ├── sepolia-addresses-example.json
│ └── sepolia-addresses.json (auto-generated)
├── deployments/ # Deployment records
│ ├── .gitignore
│ └── sepolia-deployments.json
├── hardhat.config.ts # Hardhat configuration
├── DEPLOYMENT_SEPOLIA.md # Full deployment guide
├── DEPLOYMENT_WORKFLOW.md # Quick reference
├── FRONTEND_INTEGRATION.md # Frontend guide
└── package.json # Updated with Hardhat deps
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"hardhat": "^2.22.0",
"hardhat-gas-reporter": "^1.0.10",
"solidity-coverage": "^0.8.12",
"dotenv": "^16.4.5",
"ethers": "^6.11.0",
"chai": "^4.3.10",
"@typechain/ethers-v6": "^11.1.2",
"typechain": "^8.3.2"pnpm installcp .env.example .env
# Edit .env with your credentialsRequired in .env:
SEPOLIA_RPC_URL- RPC provider URLSEPOLIA_PRIVATE_KEY- Testnet private keyETHERSCAN_API_KEY- For verification (optional)
Visit: https://sepoliafaucet.com/
Request Sepolia testnet ETH (need ~ 0.1 ETH for deployment)
pnpm contract:deploy:sepolia- Check Etherscan link in output
- Verify frontend artifacts are saved
- Test contract interactions
1. pnpm install # Install dependencies
2. Create .env file # Add credentials
3. pnpm contract:compile # Verify contracts compile
4. Get testnet ETH # Fund account @ faucet
5. pnpm contract:test # Run tests (optional)
6. pnpm contract:deploy:sepolia # Deploy to Sepolia ⭐
7. Verify on Etherscan # Check verification status
8. Update frontend config # Use contract address
9. Test integration # Verify end-to-end
# Development
pnpm dev # Start Next.js dev server
# Contracts
pnpm contract:compile # Compile all contracts
pnpm contract:deploy:sepolia # Deploy to Sepolia ⭐
pnpm contract:deploy:local # Deploy locally
pnpm contract:test # Run unit tests
pnpm contract:test:gas # Run tests with gas reporting
pnpm contract:verify # Manually verify on Etherscan
pnpm contract:accounts # List available accounts
pnpm contract:clean # Clean build artifacts
pnpm hardhat:node # Start local node
# Database
pnpm prisma studio # Open Prisma studioAfter successful deployment:
- ✅ Contract deployed and verified on Etherscan
- ✅ ABI available at
frontend/constants/deployments/sepolia-addresses.json - ✅ Frontend can import contract configuration
- ✅ Deployment records saved locally
- ✅ Gas metrics available in reports
| File | Purpose |
|---|---|
hardhat.config.ts |
Hardhat configuration |
scripts/deploy.ts |
Deployment script |
contracts/ethereum/AjoFactory.sol |
Smart contract |
test/AjoFactory.test.ts |
Unit tests |
.env.example |
Environment template |
DEPLOYMENT_SEPOLIA.md |
Complete guide |
FRONTEND_INTEGRATION.md |
Frontend guide |
✅ Private Key Management
- Loaded from
.envenvironment variables - Never hardcoded in source
- Clear warnings in config
✅ Network Validation
- Pre-flight checks before deployment
- RPC connectivity verification
- Chain ID validation
✅ Balance Verification
- Checks account has sufficient funds
- Warns if balance is low
- Prevents failed deployments
✅ Already-Deployed Detection
- Detects previous deployments
- Prevents wasting gas on retries
- Saves deployment details locally
✅ Contract Verification
- Automated Etherscan verification
- Source code publicly viewable
- Builds trust with frontend team
Import deployment config in your frontend:
import deployments from '@/constants/deployments/sepolia-addresses.json'
const contractAddress = deployments.contracts.AjoFactory.address
const contractABI = deployments.contracts.AjoFactory.abiSee FRONTEND_INTEGRATION.md for complete examples.
Sepolia Testnet:
- Chain ID:
11155111 - RPC:
https://sepolia.infura.io/v3/YOUR_KEY - Explorer:
https://sepolia.etherscan.io/ - Faucet:
https://sepoliafaucet.com/ - Block time: ~12 seconds
- Requires testnet ETH for gas
Get gas estimates for your deployment:
pnpm contract:test:gasThis generates gas-report.txt with per-function gas costs.
- Need testnet ETH from: https://sepoliafaucet.com/
- Add
SEPOLIA_RPC_URLto.env
- Remove
0xprefix from private key - Ensure correct format in
.env
- Expected if deploying twice
- Can view existing verification on Etherscan
For more troubleshooting, see DEPLOYMENT_SEPOLIA.md.
-
DEPLOYMENT_SEPOLIA.md - Complete step-by-step guide
- Prerequisites
- Setup
- Configuration
- Deployment
- Verification
- Troubleshooting
-
DEPLOYMENT_WORKFLOW.md - Quick reference
- Commands
- Quick start
- Common operations
- Simple troubleshooting
-
FRONTEND_INTEGRATION.md - Developer guide
- Setup
- Code examples
- Component examples
- Error handling
- Event listening
✅ Modular deployment script ✅ Clear error messages ✅ Comprehensive logging ✅ Pre-flight validation ✅ Automatic verification ✅ Environment variable security ✅ Artifact organization ✅ Documentation ✅ Testing suite ✅ Gas optimization
- ✅ Review and understand the setup
- ✅ Configure
.envwith credentials - ✅ Get testnet ETH from faucet
- ✅ Run
pnpm contract:compile - ✅ Run
pnpm contract:deploy:sepolia - ✅ Verify on Etherscan
- ✅ Integrate frontend components
- ✅ Test end-to-end
- ✅ Deploy frontend
- 🚀 Monitor on testnet
For issues:
- Check relevant documentation
- Review Hardhat/Ethers.js docs
- Check Etherscan for transaction details
- Review
DEPLOYMENT_SEPOLIA.mdtroubleshooting
- Node.js v18+ installed
- Dependencies installed
-
.envfile configured - Private key added
- Testnet ETH in account
- Contracts compile successfully
- Pre-deployment test passes
- Deployed to Sepolia
- Contract verified on Etherscan
- Frontend artifacts available
- Frontend integration tested
- End-to-end testing complete
What you have: ✅ Complete Hardhat setup with Sepolia configuration ✅ Production-ready deployment script ✅ Comprehensive smart contract with tests ✅ Automated Etherscan verification ✅ Frontend integration artifacts ✅ Detailed documentation ✅ Deployment utilities ✅ Error handling and recovery
What to do next:
- Configure
.envwith your credentials - Get testnet ETH from faucet
- Run
pnpm contract:deploy:sepolia - Integrate frontend components
- Test and monitor on testnet
Ready to deploy! 🚀
Created: March 2024 Version: 1.0.0 Status: ✅ Complete and Ready