8.7 KiB
8.7 KiB
๐ Deployment Instructions - BetFun Arena
Quick Deploy Checklist
- โ Build and deploy smart contracts to Solana
- โ Update frontend with deployed program ID
- โ Configure Moddio integration
- โ Deploy frontend to Vercel
- โ Deploy indexer to Railway
- โ Test the complete flow
Step 1: Deploy Smart Contracts
Prerequisites
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install Solana CLI
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
# Install Anchor
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
avm install latest
avm use latest
Build & Deploy
# Navigate to anchor directory
cd packages/anchor
# Build the program
anchor build
# Deploy to devnet (for testing)
solana config set --url devnet
solana airdrop 2
anchor deploy --provider.cluster devnet
# OR Deploy to mainnet (for production)
solana config set --url mainnet-beta
anchor deploy --provider.cluster mainnet
Get Program ID
# After deployment, get the program ID
solana address -k target/deploy/betfun-keypair.json
# Or use the declared ID
# BetFunArenaPredictionMarketGameV1111111111111
Step 2: Update Frontend with Program ID
Update Environment Variables
Create/update apps/web/.env.local:
# Solana
NEXT_PUBLIC_SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
NEXT_PUBLIC_PROGRAM_ID=<YOUR_DEPLOYED_PROGRAM_ID>
# Supabase
NEXT_PUBLIC_SUPABASE_URL=<YOUR_SUPABASE_URL>
NEXT_PUBLIC_SUPABASE_ANON_KEY=<YOUR_SUPABASE_ANON_KEY>
# Indie.fun
NEXT_PUBLIC_INDIE_FUN_API_URL=https://api.indie.fun
INDIE_FUN_API_KEY=<YOUR_API_KEY>
# Moddio
NEXT_PUBLIC_MODDIO_WORLD_ID=<YOUR_MODDIO_WORLD_ID>
# Play Solana
NEXT_PUBLIC_PLAY_SOLANA_PROJECT_ID=<YOUR_PROJECT_ID>
PLAY_SOLANA_API_KEY=<YOUR_API_KEY>
# Sentry (optional)
NEXT_PUBLIC_SENTRY_DSN=<YOUR_SENTRY_DSN>
Step 3: Configure Moddio Integration
1. Create Moddio World
- Go to Moddio.com
- Create a new world/game
- Copy your World ID
- Configure game settings for BetFun Arena
2. Update Moddio Configuration
The frontend is already configured to use Moddio. Just update your World ID in .env.local:
NEXT_PUBLIC_MODDIO_WORLD_ID=your_world_id_here
3. Moddio World Setup
In your Moddio world, you'll need to:
-
Setup Arena Visualization
- Create two teams/sides for "Yes" and "No" outcomes
- Add visual representations for participants
- Configure animations for bets
-
Configure Event Listeners
- The frontend sends these events:
bigbet- When a large bet is placedresolution- When arena is resolvedwhale- When a whale joins
- The frontend sends these events:
-
Add Custom Scripts (Optional)
// In Moddio editor, add listener for custom events ige.on('bigbet', function(data) { // Show big bet animation console.log('Big bet:', data); }); ige.on('resolution', function(data) { // Show winner celebration console.log('Arena resolved:', data); }); ige.on('whale', function(data) { // Show whale entrance console.log('Whale joined:', data); });
Step 4: Update SDK with Program ID
Update packages/sdk/src/index.ts:
import { PublicKey } from '@solana/web3.js';
// Update this with your deployed program ID
export const PROGRAM_ID = new PublicKey('BetFunArenaPredictionMarketGameV1111111111111');
// Or use environment variable
// export const PROGRAM_ID = new PublicKey(
// process.env.NEXT_PUBLIC_PROGRAM_ID || 'BetFunArenaPredictionMarketGameV1111111111111'
// );
Step 5: Test Locally
# Install dependencies
bun install
# Start frontend
cd apps/web
bun dev
# In another terminal, start indexer
cd packages/indexer
bun dev
Navigate to http://localhost:3000 and test:
- Connect wallet
- Create an arena
- Join an arena
- Verify Moddio iframe loads
- Resolve arena (as creator)
- Claim winnings
Step 6: Deploy Frontend (Vercel)
Via CLI
cd apps/web
# Install Vercel CLI
npm i -g vercel
# Deploy
vercel --prod
Via GitHub
- Push code to GitHub
- Connect repository to Vercel
- Configure environment variables in Vercel dashboard
- Deploy automatically on push to main
Environment Variables in Vercel
Set all variables from .env.local in Vercel dashboard:
- Project Settings โ Environment Variables
- Add each variable for Production, Preview, and Development
Step 7: Deploy Indexer (Railway)
Via CLI
cd packages/indexer
# Install Railway CLI
npm i -g @railway/cli
# Login
railway login
# Initialize project
railway init
# Deploy
railway up
Via GitHub
- Push code to GitHub
- Create new project in Railway
- Connect GitHub repository
- Select
packages/indexeras root directory - Configure environment variables
- Deploy
Environment Variables in Railway
SUPABASE_URL=<YOUR_SUPABASE_URL>
SUPABASE_SERVICE_KEY=<YOUR_SERVICE_KEY>
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
HELIUS_WEBHOOK_SECRET=<YOUR_SECRET>
INDIE_FUN_API_KEY=<YOUR_KEY>
PLAY_SOLANA_API_KEY=<YOUR_KEY>
SENTRY_DSN=<YOUR_DSN>
PORT=3001
Step 8: Configure Helius Webhook
- Go to Helius Dashboard
- Create a new webhook
- Configure:
- Webhook URL:
https://your-indexer.railway.app/webhook/transaction - Webhook Type: Enhanced Transaction
- Transaction Types: All
- Account Addresses: Add your deployed program ID
- Webhook Secret: Generate and save to Railway env vars
- Webhook URL:
Step 9: Database Setup
Apply Migrations
# Using Supabase CLI
supabase db push
# Or manually in Supabase dashboard
# Copy contents of packages/indexer/supabase/migrations/*.sql
# Run in SQL Editor
Verify Tables
Check that these tables exist:
arenasparticipantsleaderboardprocessed_transactions
Step 10: Verification
Test Complete Flow
-
Create Arena
- Connect wallet on frontend
- Create a test arena
- Verify it appears in database
- Check Moddio iframe loads
-
Join Arena
- Use another wallet
- Join the arena
- Verify transaction succeeds
- Check Moddio shows both participants
-
Moddio Events
- Place a large bet (>1 SOL)
- Verify
bigbetevent fires in Moddio - Check console for event logs
-
Resolve Arena
- As creator, resolve arena
- Verify resolution appears in Moddio
- Check winner outcome is correct
-
Claim Winnings
- As winner, claim winnings
- Verify payout received
- Check creator fee distributed
Monitoring
- Check Sentry for errors
- Monitor Vercel logs
- Check Railway logs
- Verify Supabase data
Troubleshooting
Smart Contract Issues
Error: Program deployment failed
# Check balance
solana balance
# Request airdrop (devnet only)
solana airdrop 2
# Check program
solana program show <PROGRAM_ID>
Error: Account not found
# Verify program deployed
anchor keys list
# Update program ID in:
# - packages/anchor/programs/betfun/src/lib.rs (declare_id!)
# - packages/anchor/Anchor.toml
# - packages/sdk/src/index.ts
# - apps/web/.env.local
Frontend Issues
Error: Wallet connection fails
- Check RPC URL is correct
- Verify network matches (devnet/mainnet)
- Ensure wallet has SOL
Error: Transaction fails
- Check program ID is correct
- Verify RPC endpoint is working
- Check Solana network status
Moddio Issues
Error: Iframe doesn't load
- Verify World ID is correct
- Check CORS settings in Moddio
- Verify URL format in
lib/moddio/urlBuilder.ts
Error: Events not firing
- Check browser console for errors
- Verify
postMessageAPI is working - Ensure Moddio world is configured to receive events
Indexer Issues
Error: Webhook not receiving transactions
- Verify Helius webhook is configured
- Check program ID filter
- Verify webhook secret matches
- Check Railway logs
Error: Database errors
- Verify migrations applied
- Check connection string
- Verify service key permissions
Post-Deployment Checklist
- Smart contracts deployed to mainnet
- Program ID updated in all files
- Frontend deployed to Vercel
- Indexer deployed to Railway
- Helius webhook configured
- Database migrations applied
- Moddio world configured
- Environment variables set
- Test arena created successfully
- Join/resolve/claim flow tested
- Moddio integration verified
- Monitoring configured
Support
If you encounter issues:
- Check logs (Vercel, Railway, browser console)
- Verify all environment variables
- Test RPC endpoints
- Check Solana network status
- Review error messages in Sentry
Ready to launch! ๐