celo-poll/README.md
2025-12-08 16:31:19 +03:00

325 lines
8.7 KiB
Markdown

# πŸ“Š PollCelo - Daily Poll, Daily Celo
**The #1 Daily Prediction Market MiniApp on Farcaster using Celo + MiniPay (cUSD)**
PollCelo is a viral daily polling app where users vote with tiny cUSD amounts (0.01 - 0.5 cUSD), creating a pot that winners share at the end of the day. Every poll is instantly shareable as a beautiful Farcaster Frame.
## πŸš€ Features
### Core Features
- βœ… **One Daily Poll** - New poll every day at 00:00 UTC
- πŸ’° **Vote with cUSD** - Tiny amounts (0.01 - 0.5 cUSD) on Celo
- πŸ† **Win Rewards** - 95% of pot shared among winners
- πŸ–ΌοΈ **Shareable Frames** - Every poll is a beautiful Farcaster Frame
- πŸ“Š **Live Results** - Real-time voting progress
- πŸ“œ **History** - Track your wins and losses
- 🌍 **Turkish Market Focus** - USD/TRY, CBRT, and local content
- ⚑ **Almost Zero Fees** - Thanks to Celo's low transaction costs
### πŸ†• New Features (Just Added!)
- 🎁 **Referral System** - Earn 0.01 cUSD per friend who votes
- πŸ” **Smart Contract** - Trustless voting & automatic payouts
- πŸ“± **Mobile App** - Native iOS & Android app (coming soon)
## πŸ—οΈ Tech Stack
- **Frontend**: Next.js 15, React 19, TypeScript
- **Styling**: Tailwind CSS
- **Blockchain**: Celo (cUSD stablecoin)
- **Wallet**: MiniPay, Wagmi v2, Viem
- **Farcaster**: Frame SDK, Frame Wagmi Connector
- **Storage**: Upstash Redis (with in-memory fallback)
- **OG Images**: @vercel/og
- **Deployment**: Vercel
## πŸ“ Project Structure
```
daily-poll-mini-app/
β”œβ”€β”€ app/
β”‚ β”œβ”€β”€ layout.tsx # Root layout with metadata
β”‚ β”œβ”€β”€ page.tsx # Home - today's poll + voting
β”‚ β”œβ”€β”€ providers.tsx # Wagmi + React Query providers
β”‚ β”œβ”€β”€ globals.css # Global styles
β”‚ β”œβ”€β”€ poll/
β”‚ β”‚ └── [id]/
β”‚ β”‚ β”œβ”€β”€ page.tsx # Individual poll detail
β”‚ β”‚ └── layout.tsx # Poll metadata + Frame tags
β”‚ β”œβ”€β”€ history/
β”‚ β”‚ └── page.tsx # Past polls + user stats
β”‚ β”œβ”€β”€ success/
β”‚ β”‚ └── page.tsx # Vote confirmation + share
β”‚ └── api/
β”‚ └── og/
β”‚ └── route.tsx # Dynamic OG image generation
β”‚
β”œβ”€β”€ components/
β”‚ β”œβ”€β”€ Header.tsx # User info + cUSD balance
β”‚ β”œβ”€β”€ PollCard.tsx # Poll display with progress bars
β”‚ β”œβ”€β”€ VoteButton.tsx # cUSD amount selector + vote
β”‚ β”œβ”€β”€ WinnerBadge.tsx # Win/loss display
β”‚ └── FAB.tsx # Floating action button
β”‚
β”œβ”€β”€ lib/
β”‚ β”œβ”€β”€ polls.ts # Poll logic + in-memory storage
β”‚ β”œβ”€β”€ redis.ts # Upstash Redis integration
β”‚ β”œβ”€β”€ celo.ts # Celo/cUSD config + utils
β”‚ β”œβ”€β”€ wagmi-config.ts # Wagmi configuration
β”‚ └── format.ts # Formatting utilities
β”‚
β”œβ”€β”€ types/
β”‚ └── index.ts # TypeScript types
β”‚
└── public/ # Static assets
```
## πŸ› οΈ Setup Instructions
### Prerequisites
- Node.js 18+ and npm/pnpm/yarn
- Vercel account (for deployment)
- Upstash Redis account (optional, free tier)
- Wallet with cUSD on Celo (for receiving fees)
### 1. Clone and Install
```bash
cd daily-poll-mini-app
npm install
# or
pnpm install
```
### 2. Environment Variables
Copy `.env.local.example` to `.env.local`:
```bash
cp .env.local.example .env.local
```
Edit `.env.local`:
```env
# Upstash Redis (optional - app works without it)
UPSTASH_REDIS_REST_URL=https://your-redis-url.upstash.io
UPSTASH_REDIS_REST_TOKEN=your_token_here
# Celo Network
NEXT_PUBLIC_CELO_RPC_URL=https://forno.celo.org
NEXT_PUBLIC_CUSD_ADDRESS=0x765DE816845861e75A25fCA122bb6898B8B1282a
# Your wallet address (to receive protocol fees)
PROTOCOL_WALLET_ADDRESS=0xYourWalletAddressHere
# App URL (for Frames)
NEXT_PUBLIC_APP_URL=http://localhost:3000
```
### 3. Run Development Server
```bash
npm run dev
```
Open [http://localhost:3000](http://localhost:3000) in your browser.
### 4. Testing in Warpcast
1. Install Warpcast mobile app
2. Enable Developer Mode in Settings
3. Add your local URL (use ngrok for HTTPS):
```bash
ngrok http 3000
```
4. Open the ngrok URL in Warpcast
## 🚒 Deployment to Vercel
### One-Click Deploy
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/yourusername/pollcelo)
### Manual Deployment
1. Push your code to GitHub
2. Import to Vercel:
```bash
npx vercel
```
3. Add environment variables in Vercel dashboard
4. Deploy:
```bash
npx vercel --prod
```
5. Update `NEXT_PUBLIC_APP_URL` to your Vercel domain
## πŸ“ First 7 Poll Ideas (Ready to Use)
The app comes with 7 pre-configured polls perfect for Turkish users:
1. **Tomorrow 1 USD = ? TL** - Daily currency prediction
2. **Will BTC break $120K this week?** - Crypto prediction
3. **FenerbahΓ§e vs Galatasaray** - Derby winner
4. **Year-end 1 USD = ? TL** - Long-term prediction
5. **Gold hits $3,000 this month?** - Commodities
6. **Next CBRT interest rate decision** - Central bank policy
7. **ETH surpasses $5,000 in December?** - Ethereum prediction
## πŸ’° Money Flow (How It Works)
### Option A: Off-Chain (Launch Today!)
1. Users vote by sending cUSD to your `PROTOCOL_WALLET_ADDRESS`
2. Votes are recorded in Redis/memory
3. At end of day, manually distribute 95% to winners
4. Keep 5% as protocol fee
**Distribution Script** (manual):
```javascript
// See lib/distribute.ts for full implementation
const winnersPot = totalPot * 0.95
const protocolFee = totalPot * 0.05
// Transfer winnersPot proportionally to all winners
```
### Option B: On-Chain (Week 2 Upgrade)
Deploy a smart contract to automate distribution:
```solidity
contract PollDistributor {
function vote(uint256 pollId, uint256 optionId) external payable
function closePoll(uint256 pollId, uint256 correctOptionId) external
function distribute(uint256 pollId) external
}
```
## 🎨 Customization
### Adding New Polls
Edit `lib/polls.ts` and add to `SEED_POLLS`:
```typescript
{
question: 'Your question here?',
description: 'Additional context',
emoji: '🎯',
options: [
{ id: 'opt1', text: 'Option 1', emoji: 'βœ…', votes: 0, totalAmount: 0 },
{ id: 'opt2', text: 'Option 2', emoji: '❌', votes: 0, totalAmount: 0 },
],
}
```
### Changing Vote Amounts
Edit `lib/celo.ts`:
```typescript
export const VOTE_OPTIONS = [
{ amount: 0.01, label: '0.01 cUSD', emoji: 'πŸͺ™' },
{ amount: 0.05, label: '0.05 cUSD', emoji: 'πŸ’°' },
{ amount: 0.1, label: '0.1 cUSD', emoji: 'πŸ’΅' },
{ amount: 0.5, label: '0.5 cUSD', emoji: 'πŸ’Έ' },
]
```
### Customizing Colors
Edit `tailwind.config.ts`:
```typescript
colors: {
celo: {
green: '#35D07F',
yellow: '#FBCC5C',
dark: '#2E3338',
},
}
```
## πŸ”§ Troubleshooting
### Wallet Not Connecting
- Make sure you're testing in Warpcast app (not browser)
- Check that Frame SDK is initialized: `sdk.actions.ready()`
- Verify Celo RPC URL is working
### Votes Not Recording
- Check `PROTOCOL_WALLET_ADDRESS` is set correctly
- Verify user has enough cUSD + CELO for gas
- Check browser console for transaction errors
### Redis Not Working
- App works fine without Redis (uses in-memory storage)
- Verify Upstash credentials in `.env.local`
- Check Redis dashboard for connection errors
## πŸ“Š Analytics & Monitoring
Track key metrics:
- **Daily Active Users** - Unique voters per day
- **Total Volume** - cUSD voted per day
- **Win Rate** - Percentage of users who win
- **Viral Coefficient** - Shares per user
## πŸ›£οΈ Roadmap
- [x] Core voting functionality
- [x] Farcaster Frame integration
- [x] Real-time results
- [x] History tracking
- [ ] Smart contract for auto-distribution
- [ ] Referral rewards (0.01 cUSD per friend)
- [ ] Leaderboard
- [ ] Push notifications for results
- [ ] Multi-language support
- [ ] Advanced analytics dashboard
## 🀝 Contributing
Contributions welcome! Please:
1. Fork the repo
2. Create a feature branch
3. Make your changes
4. Submit a pull request
## πŸ“„ License
MIT License - see LICENSE file for details
## πŸ†˜ Support
- GitHub Issues: [Report a bug](https://github.com/yourusername/pollcelo/issues)
- Farcaster: [@yourusername](https://warpcast.com/yourusername)
- Email: your@email.com
## πŸŽ‰ Ready to Launch?
You now have a fully functional daily poll MiniApp that:
βœ… Works on Farcaster with MiniPay
βœ… Uses cUSD on Celo (almost zero fees)
βœ… Has beautiful shareable Frames
βœ… Includes 7 pre-made Turkish market polls
βœ… Can be deployed to Vercel in minutes
**Let's ship this and get thousands of users voting with cUSD tomorrow! πŸš€**
---
Built with ❀️ for the Farcaster + Celo community
# celo-poll