3.1 KiB
3.1 KiB
PollCelo Mini-App Walkthrough
Overview
PollCelo is a Farcaster Mini-App that allows users to create and vote on daily polls. It features:
- Poll Creation: Users pay 5 cUSD (on Celo) to create a poll.
- Real-time Rates: Fetches USD/TRY rates from DexScreener for prediction polls.
- Automated Verification: Verifies poll results using external APIs (e.g., checking if the rate hit a target).
- Prize Distribution: Automatically distributes the pot to winners via cron jobs.
Features Implemented
1. Database & Backend
- Neon PostgreSQL: Stores polls, options, votes, and distributions.
- Drizzle ORM: Type-safe database interactions.
- Hono API:
GET /api/poll: Fetch active polls.POST /api/vote: Record votes.POST /api/create-poll: Create new polls with payment validation.GET /api/rates: Real-time cUSD and USD/TRY rates.GET /api/cron/verify: Cron job to verify ended polls.GET /api/cron/distribute: Cron job to distribute prizes.
2. Frontend
- React + Vite: Fast and responsive UI.
- Wagmi + Viem: Wallet connection and transaction handling (Celo Alfajores).
- Pages:
- Home: View active poll, vote, and see real-time rates.
- Create Poll: Form to create a new poll with a 5 cUSD fee.
3. Automation
- Verification Logic: Checks external data sources to validate poll outcomes.
- Distribution Logic: Calculates winners and sends payments from the protocol wallet.
How to Test
Prerequisites
- Environment Variables: Ensure
.dev.varsinbackend/has:DATABASE_URL: Your Neon DB connection string.PROTOCOL_PRIVATE_KEY: Private key for the protocol wallet (for distribution).
- Dependencies: Run
pnpm installin bothfrontendandbackend.
Running Locally
-
Start Backend:
cd backend pnpm devRuns on
http://localhost:8787(or similar port). -
Start Frontend:
cd frontend pnpm devRuns on
http://localhost:5173.
End-to-End Flow
- Connect Wallet: Open the frontend and connect your wallet (Celo Alfajores).
- Create Poll:
- Click the "+" button.
- Enter a question (e.g., "Will USD/TRY > 35?").
- Enter options (e.g., "Yes", "No").
- Select "External API" verification.
- Click "Pay 5 cUSD & Create".
- Approve the transaction in your wallet.
- Vote:
- Go back to Home.
- See your new poll.
- Click an option to vote (Note: Voting requires
POST /api/voteintegration with wallet signature, currently mocked in UI).
- Verification (Simulated):
- Manually trigger the cron:
curl http://localhost:8787/api/cron/verify. - If the poll has ended (you might need to adjust
endTimein DB for testing), it will be verified.
- Manually trigger the cron:
- Distribution (Simulated):
- Manually trigger the cron:
curl http://localhost:8787/api/cron/distribute. - Winners will receive their share.
- Manually trigger the cron:
Deployment
- Backend:
cd backend && pnpm run deploy(Deploys to Cloudflare Workers). - Frontend: Build with
pnpm buildand deploy to Vercel/Netlify (configure proxy or update API URL).