Spin the Bottle – Technical Overview
A decentralized gambling game demonstrating advanced Solana smart contract development and modern web technologies.
🎯 Game Mechanics
Core Gameplay
- Players bet SOL to enter the round
- Higher stakes = proportionally higher winning odds
- Winner-takes-all prize distribution
- Automated payouts via smart contract
Randomness Algorithm
- Weighted probability based on bet amounts
- Uses Solana Clock timestamp for entropy
- Cumulative distribution function selection
- Transparent and verifiable on-chain
⚙️ Smart Contract Architecture
Technical Stack
- Anchor Framework v0.31.1
- Solana Runtime v1.18.20
- Rust for smart contract logic
- TypeScript for client integration
Contract Details
- Program ID:
6wLA2Z4756SLseTWmhUkdzbA1BF8evht5E8yEcE38bdo
- Network: Solana Devnet
- Account Model: Program Derived Addresses (PDAs)
- Security: Anchor security constraints
Core Functions
initialize()
Creates GameState PDA and vault for secure fund management
bet(amount)
Transfers SOL to vault, records player in participants array
spin()
Executes weighted random selection, transfers prize to winner
🎨 User Experience
Interactive Spinning Wheel
Hardware-accelerated graphics with psychedelic visual effects
Real-time Updates
Live blockchain data and transaction monitoring
Seamless Wallet Integration
One-click betting with instant confirmations
💰 Transaction Economics
Gas Costs (Devnet)
Initialize Game:~890,880 lamports
Place Bet:~5,000-10,000 lamports
Execute Spin:~10,000 lamports
Total Per Game:~$0.019 USD
Betting Strategy
- Minimal Stakes: Test with 1-3 lamports
- Cost Efficiency: Hundreds of games for ~$0.50
- Fair Distribution: Probability ∝ bet amount
- Instant Settlement: Automated prize distribution
🔒 Why It's Provably Fair
Transparent Randomness
- On-chain entropy: Uses Solana Clock timestamp for randomness
- Verifiable algorithm: Weighted probability based on bet amounts
- Public execution: All calculations happen on-chain
- No hidden parameters: Complete algorithm visibility
Immutable Smart Contract
- Code cannot be changed: Smart contract is deployed and immutable
- No admin backdoors: No functions to manipulate outcomes
- Automatic execution: Winner selection runs deterministically
- Instant payouts: Prize automatically sent to winner's wallet
How the Selection Works
The winner is selected using a weighted probability algorithm that's completely transparent:
- Random number generated from blockchain timestamp
- Number mapped to range [0, total_prize_pool)
- Players ordered by bet placement time
- Cumulative sum calculated until random number is exceeded
- Winner automatically determined and paid
Result: Higher bets = higher probability, but no manipulation possible.