Solana Coin Flip
On-chain inspired coin flip betting game built on Solana with wallet integration and backend verification.
Overview
FlipFi is a Web3 betting game where users connect their wallet, choose between heads or tails, and place a bet using SOL.
The game combines on-chain transactions with backend verification to ensure that every bet is backed by a real blockchain transaction. Once a user submits a bet, the transaction signature is validated server-side, and the result is determined.
Winnings are distributed based on the outcome, with successful bets returning nearly 2x the wager after platform fees.
Architecture
The system follows a hybrid Web2 + Web3 flow:
- User connects a Solana wallet
- User selects heads or tails and enters a bet amount
- A transaction is created and sent to the Solana network
- The transaction signature is sent to the backend
- Backend verifies the transaction via RPC
- Game result is generated
- Outcome and transaction details are stored in PostgreSQL
- If the user wins, payout is processed
- Recent transactions are displayed in the UI
Key Features
Wallet Integration
- Solana wallet connection using Wallet Adapter
- Seamless transaction signing experience
- Real-time wallet interaction
Betting Mechanism
- Choose between heads or tails
- Place bets in SOL
- Transparent input-driven gameplay
Transaction Verification
- Backend verifies transaction signatures via RPC
- Ensures bets are legitimate before processing
- Prevents fake or replayed submissions
Game Logic
- Randomized outcome generated on backend
- Win condition returns ~2x reward minus fees
- Loss results in forfeited bet
Database & Persistence
- PostgreSQL used for storing:
- Game results
- Transaction signatures
- Bet amounts
- Displays last 10 recent transactions for transparency
Real-Time UI
- Instant feedback on game results
- Recent activity feed
- Clean and responsive interface
Limitations & Improvements
- Game randomness is currently handled off-chain via backend
- This introduces trust assumptions
Planned Improvements:
- Move randomness and result generation fully on-chain using a custom program
- Use a Solana program for provable fairness
- Integrate verifiable randomness (e.g. VRF)
- Automate payouts via smart contract logic
Why I Built This
- To understand how wallet integrations actually work beyond theory
- To learn the full lifecycle of a Solana transaction
- To bridge on-chain actions with backend validation
- To explore real-world Web3 dApp architecture
- To get hands-on with building a complete betting system end-to-end
