A production-ready, provably fair dice casino game built on Solana using the Anchor framework and ORAO VRF (Verifiable Random Function) for cryptographically verifiable randomness. Players can bet SOL or SPL tokens on roll under/over outcomes with transparent, on-chain fairness verification.
- Provably Fair: Uses ORAO VRF for cryptographically verifiable randomness - every roll can be independently verified
- Flexible Betting: Support for both native SOL and SPL tokens
- Configurable House Edge: Adjustable house edge (default 2-5%) with transparent payout calculations
- On-Chain Transparency: All bet states, results, and payouts are stored on-chain for full auditability
- Secure PDAs: Program Derived Addresses (PDAs) ensure secure fund management
- Event Logging: Comprehensive event emission for off-chain indexing and analytics
- Timeout Protection: Automatic timeout handling for VRF requests to prevent stuck bets
- Production Ready: Includes comprehensive test suite, error handling, and security best practices
- Rust: Core program logic
- Anchor 0.30.1: Solana framework for smart contract development
- Solana: High-performance blockchain platform
- ORAO VRF: Fast, cheap verifiable randomness (0.001 SOL per request)
- SPL Tokens: Support for custom token betting
- TypeScript/Mocha: Comprehensive test suite
- Rust (latest stable)
- Solana CLI (v1.18+)
- Anchor (v0.30.1)
- Node.js (v18+) and Yarn/npm
- Basic knowledge of Solana and Anchor framework
git clone <repository-url>
cd Solana-Fair-Dice-Game-1# Install Rust dependencies (handled by Anchor)
anchor build
# Install Node.js dependencies
yarn install
# or
npm install# Set to devnet for testing
solana config set --url devnet
# Or use localnet
solana config set --url localhostanchor buildThis will:
- Compile the Rust program
- Generate the IDL (Interface Definition Language)
- Create the program keypair
# Ensure you have SOL for deployment fees
solana airdrop 2 $(solana address)
# Deploy the program
anchor deploy# Run all tests
anchor test
# Or run with local validator
anchor test --skip-local-validator-
Choose Your Bet:
- Target: A number between 1-99
- Side: Under (roll < target) or Over (roll > target)
- Amount: Bet amount in SOL or SPL tokens
-
Payout Calculation:
- Under bet: Multiplier = (100 / target) × (1 - house_edge)
- Over bet: Multiplier = (100 / (100 - target)) × (1 - house_edge)
- Example: Target 50, house edge 2% → ~1.96x payout
-
Randomness:
- VRF generates a random number (0-99)
- Win if: (under && roll < target) || (over && roll > target)
- Loss otherwise
-
Commit Phase (
place_bet):- Player commits bet parameters (target, side, amount)
- VRF request is created with a unique seed
- Bet state is stored on-chain with pending status
-
Reveal Phase (
fulfill_bet):- ORAO VRF generates cryptographically verifiable randomness
- Random number is mapped to 0-99 range
- Win/loss is determined deterministically
- Payout is calculated and transferred if won
-
Verification:
- Anyone can verify the VRF result off-chain using ORAO's verification tools
- Bet state account contains all necessary data for verification
- VRF request account stores the cryptographic proof
programs/fair-dice-game/
├── src/
│ ├── lib.rs # Main program entry point
│ ├── state.rs # Account structs (GameConfig, BetState)
│ └── error.rs # Custom error types
- GameConfig: Stores house settings, authority, statistics
- BetState: Per-bet tracking with VRF request ID, status, result
- Vault PDA: Holds house funds (SOL or SPL tokens)
- VRF Request: Managed by ORAO program, contains randomness proof
initialize: Create game config and set house parametersplace_bet: Transfer bet to vault, request VRF, create bet statefulfill_bet: Consume VRF result, determine outcome, transfer payoutwithdraw_house: House authority withdraws profitsupdate_config: Update house edge, timeout, fee wallet
- Telegram: https://t.me/CasinoCutup
- Twitter: https://x.com/CasinoCutup