celo-poll/SETUP_GUIDE.md
2025-12-08 16:31:30 +03:00

262 lines
5.2 KiB
Markdown

# 🚀 PollCelo Production Setup Guide
## Step 1: Clone and Install
```bash
cd daily-poll-mini-app
npm install
```
## Step 2: Generate Protocol Wallet
Generate a new wallet for the protocol (DO NOT use your personal wallet):
```bash
npm run wallet:generate
```
This will output:
- Wallet address
- Private key
- Mnemonic phrase
**⚠️ SECURITY:**
- Keep the private key PRIVATE
- Never commit to git
- Store mnemonic offline as backup
- Fund with small amount of CELO for gas
## Step 3: Set Up Neon Database
### 3.1 Create Neon Account
1. Go to [neon.tech](https://neon.tech)
2. Sign up / Log in
3. Create new project: "pollcelo-prod"
### 3.2 Get Connection String
1. Click on your project
2. Go to "Connection Details"
3. Copy the connection string
4. It looks like: `postgresql://user:password@ep-xxx.us-east-2.aws.neon.tech/neondb?sslmode=require`
### 3.3 Run Database Schema
```bash
# Set your DATABASE_URL first
export DATABASE_URL="your_connection_string_here"
# Run schema (using psql)
psql $DATABASE_URL < database/schema.sql
# Or use Neon's SQL editor in the dashboard
```
## Step 4: Configure Environment
Copy the example file:
```bash
cp .env.local.example .env.local
```
Edit `.env.local` and fill in:
```env
# ========================================
# Database
# ========================================
DATABASE_URL=postgresql://user:password@ep-xxx.neon.tech/neondb?sslmode=require
# ========================================
# Protocol Wallet (from Step 2)
# ========================================
PROTOCOL_WALLET_ADDRESS=0xYourAddressFromStep2
PROTOCOL_WALLET_PRIVATE_KEY=0xYourPrivateKeyFromStep2
# ========================================
# Celo
# ========================================
NEXT_PUBLIC_CELO_RPC_URL=https://forno.celo.org
NEXT_PUBLIC_CUSD_ADDRESS=0x765DE816845861e75A25fCA122bb6898B8B1282a
# ========================================
# App
# ========================================
NEXT_PUBLIC_APP_URL=http://localhost:3000
# ========================================
# Security
# ========================================
CRON_SECRET=$(openssl rand -hex 32)
```
## Step 5: Fund Protocol Wallet
### 5.1 Get CELO for Gas
```bash
# Testnet (Alfajores)
# Use faucet: https://faucet.celo.org/
# Mainnet
# Buy CELO on exchange and send to your protocol wallet
# You need ~1 CELO for gas fees
```
### 5.2 Get cUSD
```bash
# Swap CELO for cUSD on:
# - Ubeswap: https://app.ubeswap.org/
# - Mento: https://app.mento.org/
# You need some cUSD in the wallet for testing
```
## Step 6: Test Locally
```bash
npm run dev
```
Open [http://localhost:3000](http://localhost:3000)
### Test Checklist:
- [ ] App loads without errors
- [ ] Database connection works
- [ ] Can view today's poll (if any)
- [ ] Wallet connects via MiniPay
## Step 7: Test with Ngrok + Warpcast
### 7.1 Start Ngrok
```bash
ngrok http 3000
```
Copy the HTTPS URL (e.g., `https://abc123.ngrok.io`)
### 7.2 Update Environment
```bash
# Add to .env.local
NEXT_PUBLIC_APP_URL=https://abc123.ngrok.io
```
Restart dev server:
```bash
npm run dev
```
### 7.3 Test in Warpcast
1. Open Warpcast mobile app
2. Settings → Advanced → Enable Developer Mode
3. Create a cast with your ngrok URL
4. Tap to open as MiniApp
5. Test the full flow!
## Step 8: Deploy to Vercel
### 8.1 Push to GitHub
```bash
git init
git add .
git commit -m "Initial commit: PollCelo production ready"
git remote add origin https://github.com/yourusername/pollcelo.git
git push -u origin main
```
### 8.2 Deploy to Vercel
1. Go to [vercel.com](https://vercel.com)
2. Import your GitHub repository
3. Add all environment variables from `.env.local`
4. Deploy!
### 8.3 Update Environment
After deployment, update:
```bash
NEXT_PUBLIC_APP_URL=https://your-app.vercel.app
```
Redeploy!
## Step 9: Configure Cron Jobs
In `vercel.json`:
```json
{
"crons": [
{
"path": "/api/cron/verify",
"schedule": "0 * * * *"
},
{
"path": "/api/cron/distribute",
"schedule": "15 * * * *"
}
]
}
```
## Step 10: Create Your First Poll!
Navigate to `/create-poll` and:
1. Enter question
2. Add 2-4 options
3. Select verification method (Chainlink/Curve/API)
4. Configure verification
5. Pay 5 cUSD
6. Poll goes live!
## Monitoring
### Check Database
```bash
psql $DATABASE_URL
\dt # List tables
SELECT * FROM polls;
SELECT * FROM votes;
```
### Check Wallet Balance
```bash
# Check cUSD balance of protocol wallet
# Use Celo Explorer: https://explorer.celo.org/
```
### Check Logs
```bash
# Vercel dashboard → Your project → Logs
# Or use CLI:
vercel logs
```
## Troubleshooting
### Database Connection Failed
- Check DATABASE_URL is correct
- Verify SSL mode is set
- Check Neon project is not paused
### Wallet Transactions Failing
- Check wallet has CELO for gas
- Verify private key is correct
- Check RPC endpoint is working
### Cron Jobs Not Running
- Verify CRON_SECRET is set
- Check Vercel logs for errors
- Ensure cron paths match API routes
### Polls Not Verifying
- Check oracle API keys are set
- Verify end time has passed
- Check verification_attempts table for errors
## Next Steps
✅ You're now production ready!
1. Create your first real poll
2. Share on Farcaster
3. Monitor for votes
4. Watch automated verification work
5. See winners get paid automatically!
**Need help?** Check the docs or reach out!