7.1 KiB
7.1 KiB
๐ BetFun Arena - Environment Variables Setup Guide
OFFICIAL sponsor APIs from SPONSOR_APIS.md
Quick Start Checklist
Before deploying, you need:
- Supabase account (database)
- Solana wallet with devnet SOL
- Indie.fun API key (for token launch bonus)
- Moddio World ID (for multiplayer bonus)
- Play Solana API key (for leaderboard bonus)
- Pyth (no setup needed - public endpoint)
1. Supabase Setup (Required)
Get Credentials
- Go to https://supabase.com
- Create new project
- Go to Settings โ API
- Copy:
- Project URL
anonpublickeyservice_rolesecretkey (keep private!)
Add to Frontend (.env.local)
NEXT_PUBLIC_SUPABASE_URL=https://xxxxx.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbG...
Add to Indexer (.env)
SUPABASE_URL=https://xxxxx.supabase.co
SUPABASE_SERVICE_KEY=eyJhbG... (secret key)
Run Migrations
cd packages/indexer
# Copy SQL from supabase/migrations/001_init_schema.sql
# Paste into Supabase SQL Editor and run
2. Indie.fun API Key (Required for Bonus)
Get API Key
- Go to https://indie.fun
- Connect wallet
- Go to Dashboard โ API Keys
- Create new key: "BetFun Arena Hackathon"
- Copy the key
Add to Frontend
NEXT_PUBLIC_INDIE_FUN_API_KEY=if_live_xxxxxxxxxxxxx
Test Integration
// Should work in create arena form
const { tokenMint } = await launchToken({
name: "Test Arena Token",
symbol: "TEST",
description: "Test",
creatorWallet: publicKey.toString(),
});
console.log("Token launched:", tokenMint);
API Endpoint: https://api.indie.fun/v1/tokens/create
3. Moddio World Setup (Required for Bonus)
Create World
- Go to https://www.modd.io/create
- Click "New World"
- Name: "BetFun Arena Battle"
- Follow setup guide in
moddio/WORLD_SETUP.md
Upload Assets
Upload from moddio/assets/:
- yes_zone.png
- no_zone.png
- player_spritesheet.png
- confetti particles
Add Scripts
Copy scripts from moddio/WORLD_SETUP.md:
- Player join handler
- Big bet alerts
- Victory effects
Publish & Get Credentials
- Click "Publish"
- Copy World ID (from URL)
- Go to Settings โ API
- Copy Secret Key
Add to Environment
NEXT_PUBLIC_MODDIO_WORLD_ID=abc123def456
NEXT_PUBLIC_MODDIO_SECRET_KEY=moddio_secret_xxxxx
Embed URL Format: https://modd.io/play/{WORLD_ID}?arena=xxx&side=yes
4. Play Solana API Key (Required for Bonus)
Get API Key
- Go to https://play.solana.com (or docs.play.solana.com)
- Sign up / Connect wallet
- Create project: "BetFun Arena"
- Copy API key
Add to Environment
NEXT_PUBLIC_PLAY_SOLANA_API_KEY=ps_live_xxxxxxxxxx
Project ID (Fixed)
# Already in constants.ts
PLAY_SOLANA_PROJECT_ID=betfun-arena-2025
Test Integration
import { PlaySolana } from '@play-solana/sdk';
PlaySolana.init({ projectId: "betfun-arena-2025" });
// Submit score after win
await PlaySolana.leaderboard.submit({
leaderboardId: "total-won-sol",
score: winningsInLamports,
wallet: publicKey,
});
5. Pyth Network (No Setup Needed!)
Already Configured โ
Price feed IDs hardcoded in lib/constants.ts:
PYTH_PRICE_FEEDS = {
SOL_USD: "H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG",
BTC_USD: "GVXRSBjFkH2zqMT2iZ6yEy4v941qtn5zB6h8TZ2zM3uQ",
WIF_USD: "Ef1pB4Tga2tA9P3N3dBWMQ1sSifD3pjHLCmBiMdX4j3g",
}
Endpoint: https://hermes.pyth.network
No API key required - public endpoint works!
6. Solana Configuration
Devnet (Testing)
NEXT_PUBLIC_NETWORK=devnet
NEXT_PUBLIC_RPC_URL=https://api.devnet.solana.com
Mainnet (Production)
NEXT_PUBLIC_NETWORK=mainnet
NEXT_PUBLIC_RPC_URL=https://api.mainnet-beta.solana.com
# Or use Helius/QuickNode for better performance
7. Full Environment Files
Frontend: apps/web/.env.local
# Solana
NEXT_PUBLIC_NETWORK=devnet
NEXT_PUBLIC_RPC_URL=https://api.devnet.solana.com
# Supabase
NEXT_PUBLIC_SUPABASE_URL=https://xxxxx.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbG...
# Indie.fun (REQUIRED for bonus)
NEXT_PUBLIC_INDIE_FUN_API_KEY=if_live_xxxxx
# Moddio (REQUIRED for bonus)
NEXT_PUBLIC_MODDIO_WORLD_ID=abc123
NEXT_PUBLIC_MODDIO_SECRET_KEY=moddio_secret_xxx
# Play Solana (REQUIRED for bonus)
NEXT_PUBLIC_PLAY_SOLANA_API_KEY=ps_live_xxxxx
# App
NEXT_PUBLIC_APP_URL=http://localhost:3000
NEXT_PUBLIC_INDEXER_API_URL=http://localhost:3001
Indexer: packages/indexer/.env
# Supabase
SUPABASE_URL=https://xxxxx.supabase.co
SUPABASE_SERVICE_KEY=eyJhbG... (service role key!)
# Moddio (for webhooks)
MODDIO_SECRET_KEY=moddio_secret_xxx
MODDIO_WORLD_ID=abc123
# Solana
RPC_URL=https://api.devnet.solana.com
# Server
PORT=3001
NODE_ENV=development
8. Verification Checklist
Test Each Integration
Supabase:
curl https://YOUR_PROJECT.supabase.co/rest/v1/arenas \
-H "apikey: YOUR_ANON_KEY"
# Should return empty array or arenas
Indie.fun:
curl https://api.indie.fun/v1/tokens/create \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"name":"Test","symbol":"TEST","description":"Test"}'
# Should return token_mint_address
Moddio:
# Open in browser:
https://modd.io/play/YOUR_WORLD_ID?arena=test&side=yes
# Should load game world
Play Solana:
// In browser console on your site:
PlaySolana.leaderboard.submit({...})
// Should not error
Pyth:
curl "https://hermes.pyth.network/api/latest_price_feeds?ids[]=H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG"
# Should return SOL price
9. Common Issues
"Indie.fun API error: 401"
- Check API key is correct
- Check it's
Bearer YOUR_KEYformat - Verify key hasn't expired
"Moddio world not loading"
- Check World ID is correct (from published URL)
- Verify world is published (not draft)
- Check iframe src format:
https://modd.io/play/{ID}
"Supabase RLS error"
- Check migrations ran successfully
- Verify RLS policies are enabled
- Use service key for server-side calls
"Pyth price not found"
- Check price feed ID is exact (case-sensitive)
- Verify Pyth is online: https://pyth.network/developers/price-feed-ids
10. Security Best Practices
โ DO:
- Use
.env.localfor frontend (gitignored) - Use
.envfor indexer (gitignored) - Use service role key only server-side
- Rotate keys after hackathon
โ DON'T:
- Commit
.envfiles to git - Share service role keys publicly
- Use production keys in frontend
- Hardcode secrets in code
11. Deployment Environment Variables
Vercel (Frontend)
- Go to Project Settings โ Environment Variables
- Add all
NEXT_PUBLIC_*vars - Separate production/preview/development
Railway (Indexer)
- Go to Variables tab
- Add all server vars (no
NEXT_PUBLIC_prefix) - Click "Deploy"
All endpoints verified from SPONSOR_APIS.md
No placeholders - these are production-ready APIs
Need help? Check:
SPONSOR_APIS.md- Official API docsREADME.md- General setupdocs/DEPLOYMENT.md- Full deploy guide
Status: Ready to configure! โก