A complete NFT-based blessing and governance system with:
-
Privy Authentication Middleware (src/middleware/auth.ts)
- Verifies Privy JWT tokens
- Extracts wallet addresses from authenticated users
-
NFT Snapshot Generator (lib/snapshots/firstWorksSnapshot.ts)
- Fetches all FirstWorks NFT ownership data from L1 Ethereum
- Saves to
lib/snapshots/latest.json - Should be run daily via cron
-
Merkle Tree Generator (lib/snapshots/merkleTreeGenerator.ts)
- Creates cryptographic proofs for each NFT holder
- Enables cross-chain ownership verification on L2
-
Contract Service (src/services/contractService.ts)
- Interacts with AbrahamSeeds contract on Base
- Handles seed submission, blessings, and winner selection
-
AbrahamSeeds (L2 Base) - Main governance contract
- Seed submission and curation
- Blessing (voting) system with Merkle proof verification
- Daily winner selection
- ERC1155 NFT minting for winners
-
MerkleGating (L2 Base) - Cross-chain verification module
- Verifies L1 NFT ownership via Merkle proofs
- Enables gasless blessings with proof verification
- Seeds:
GET/POST /api/seeds/*- Seed management and queries - Blessings:
GET/POST /api/blessings/*- Blessing eligibility and submission - Commandments:
GET/POST /api/commandments/*- Comments on seeds - Leaderboard:
GET /api/leaderboard/*- User rankings - Admin:
GET/POST /api/admin/*- Admin operations and cron jobs
cp .env.example .env.localEdit .env.local:
# Privy Authentication
PRIVY_APP_ID=your_privy_app_id
PRIVY_APP_SECRET=your_privy_app_secret
# FirstWorks NFT Contract (L1 Ethereum)
FIRSTWORKS_CONTRACT_ADDRESS=0x9734c959A5FEC7BaD8b0b560AD94F9740B90Efd8
FIRSTWORKS_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY
# AbrahamSeeds Contract (L2 Base Sepolia)
L2_SEEDS_CONTRACT=0x0b95d25463b7a937b3df28368456f2c40e95c730
L2_GATING_CONTRACT=0x46657b69308d90a4756369094c5d78781f3f5979
L2_SEEDS_DEPLOYMENT_BLOCK=36452477
NETWORK=baseSepolia
# RPC URLs
BASE_SEPOLIA_RPC_URL=https://base-sepolia.g.alchemy.com/v2/YOUR_KEY
MAINNET_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY
# Private Keys (for backend relayer)
RELAYER_PRIVATE_KEY=your_relayer_private_key
# Admin & API Keys
ADMIN_KEY=your_admin_key
CRON_SECRET=your_cron_secret
ALCHEMY_API_KEY=your_alchemy_key# Fetch NFT ownership from L1
npm run snapshot:generate
# Generate Merkle tree for proofs
npm run merkle:generate# Development mode with hot reload
npm run dev
# OR production mode
npm start# Health check
curl http://localhost:3000
# Get seed count
curl http://localhost:3000/api/seeds/count
# Get current voting stats
curl http://localhost:3000/api/seeds/stats
# Get contract config
curl http://localhost:3000/api/seeds/config
# Get seed by ID
curl http://localhost:3000/api/seeds/0
# Get leaderboard
curl http://localhost:3000/api/leaderboard
# Get snapshot status
curl http://localhost:3000/api/admin/snapshot-statusnpm run compilenpm run deploy:abraham-seeds:base-sepoliaThis deploys:
- MerkleGating module
- AbrahamSeeds contract
- Grants CREATOR_ROLE and OPERATOR_ROLE
- Updates Merkle root
- Creates a test seed
npm run deploy:abraham-seeds:baseAfter generating a new snapshot, update the on-chain Merkle root:
npm run update-rootnpm run test:contracts+-------------------------------------------------------------+
| Ethereum L1 (Mainnet) |
+-------------------------------------------------------------+
| |
| Abraham's First Works (Already Deployed) |
| Address: 0x9734c959A5FEC7BaD8b0b560AD94F9740B90Efd8 |
| - 2,044 NFTs - ownership = blessing power on L2 |
| |
+-------------------------------------------------------------+
|
| Daily Snapshot -> Merkle Tree
v
+-------------------------------------------------------------+
| Base L2 |
+-------------------------------------------------------------+
| |
| MerkleGating Module |
| Address: 0x46657b69308d90a4756369094c5d78781f3f5979 |
| - Stores Merkle root for ownership verification |
| |
| AbrahamSeeds Contract |
| Address: 0x0b95d25463b7a937b3df28368456f2c40e95c730 |
| - Seed submission (IPFS hash) |
| - Blessing/voting (with Merkle proof verification) |
| - Commandments (comments on seeds) |
| - Daily winner selection |
| - ERC1155 NFT minting for winners |
| |
+-------------------------------------------------------------+
| Script | Description |
|---|---|
npm run dev |
Start dev server with hot reload |
npm start |
Start production server |
npm run snapshot:generate |
Generate FirstWorks NFT snapshot |
npm run merkle:generate |
Generate Merkle tree from snapshot |
npm run update-snapshot |
Full update: snapshot + merkle + contract |
| Script | Description |
|---|---|
npm run compile |
Compile Solidity contracts |
npm run deploy:abraham-seeds:base-sepolia |
Deploy to Base testnet |
npm run deploy:abraham-seeds:base |
Deploy to Base mainnet |
npm run update-root |
Update Merkle root on contract |
npm run test:contracts |
Run contract tests |
npm run grant-creator:base-sepolia |
Grant CREATOR_ROLE |
abraham-api/
+-- contracts/
| +-- src/
| +-- agents/abraham/AbrahamSeeds.sol # Main governance contract
| +-- modules/gating/MerkleGating.sol # Cross-chain gating module
| +-- core/EdenAgent.sol # Base agent contract
+-- lib/
| +-- abi/
| | +-- AbrahamSeeds.json # Contract ABI
| | +-- MerkleGating.json # Gating module ABI
| | +-- firstWorks.ts # FirstWorks NFT ABI
| +-- snapshots/
| +-- firstWorksSnapshot.ts # Snapshot generator
| +-- merkleTreeGenerator.ts # Merkle tree generator
| +-- latest.json # Generated snapshot
| +-- firstWorks_merkle.json # Merkle tree & proofs
+-- src/
| +-- middleware/
| | +-- auth.ts # Privy authentication
| +-- routes/
| | +-- seeds.ts # Seed endpoints
| | +-- blessings.ts # Blessing endpoints
| | +-- commandments.ts # Comment endpoints
| | +-- leaderboard.ts # Leaderboard endpoints
| | +-- admin.ts # Admin endpoints
| +-- services/
| | +-- contractService.ts # Contract interactions
| | +-- blessingService.ts # Blessing logic
| | +-- commandmentService.ts # Commandment logic
| | +-- leaderboardService.ts # Leaderboard logic
| +-- index.ts # Hono app
| +-- server.ts # Server entry
+-- deploy/
| +-- deploy_abraham_seeds.ts # Deployment script
+-- scripts/
| +-- updateMerkleRoot.ts # Update Merkle root
| +-- updateSnapshot.ts # Full snapshot update
+-- .env.local # Environment variables
+-- hardhat.config.ts # Hardhat configuration
+-- package.json
Set up automated daily operations via Vercel cron:
{
"crons": [
{
"path": "/api/admin/update-snapshot",
"schedule": "0 1 * * *"
},
{
"path": "/api/admin/select-winner?autoElevate=true",
"schedule": "0 0 * * *"
}
]
}- Run
npm run snapshot:generatefirst - Verify RPC URL is correct in
.env.local
- Check Privy credentials in
.env.local - Ensure client is sending valid Privy JWT
- Verify L2_SEEDS_CONTRACT is set correctly
- Check BASE_SEPOLIA_RPC_URL is valid
- Regenerate Merkle tree:
npm run merkle:generate - Update contract root:
npm run update-root
- Smart Contract Summary - Contract architecture
- API Reference - Complete API documentation
- Deployment Guide - Deployment instructions
- Blessing System - How blessings work
Ready to go! Run npm run snapshot:generate && npm run merkle:generate then npm run dev to start.