A fully decentralized, on-chain jackpot gambling game built on Solana blockchain. Players deposit SOL tokens into a shared pot, and a winner is randomly selected to claim the entire jackpot. Built with Anchor framework, featuring real-time updates via WebSocket and a modern Next.js frontend.
- Features
- Tech Stack
- Architecture
- Prerequisites
- Installation
- Configuration
- Usage
- Project Structure
- Smart Contract
- API Endpoints
- Security Notes
- Contributing
- License
- Contact
- 🎲 Decentralized Game Logic: Fully on-chain smart contract ensures transparency and fairness
- ⚡ Real-time Updates: WebSocket integration for live game state updates
- 💰 Multi-player Support: Multiple players can join the same jackpot pool
- 🔐 Secure Transactions: All transactions verified on Solana blockchain
- 📱 Modern UI: Responsive Next.js frontend with Tailwind CSS
- 💬 Live Chat: Integrated chat system for player interaction
- 📊 Game Statistics: Track wagered amounts, player counts, and game history
- 🎯 Provably Fair: Random winner selection based on on-chain data
- Next.js 12 - React framework
- TypeScript - Type-safe development
- Tailwind CSS - Utility-first CSS framework
- Socket.IO Client - Real-time communication
- @solana/wallet-adapter - Solana wallet integration
- React Query - Data fetching and caching
- Node.js + Express - RESTful API server
- TypeScript - Type-safe backend
- Socket.IO - WebSocket server for real-time updates
- MongoDB + Mongoose - Database for game state and messages
- @solana/web3.js - Solana blockchain interaction
- @project-serum/anchor - Anchor framework integration
- Anchor Framework - Solana program development
- Rust - Smart contract language
- Solana Program Library (SPL) - Token and system programs
┌─────────────────┐
│ Frontend │
│ (Next.js) │
└────────┬─────────┘
│ HTTP/WebSocket
│
┌────────▼─────────┐
│ Backend │
│ (Express) │
└────────┬─────────┘
│
┌────┴────┐
│ │
┌───▼───┐ ┌──▼────┐
│MongoDB│ │Solana │
│ │ │Network│
└───────┘ └───────┘
- Player Action: User connects wallet and deposits SOL via frontend
- Transaction: Frontend creates and signs Solana transaction
- Blockchain: Transaction is submitted to Solana network
- Backend Monitoring: Backend monitors blockchain for new transactions
- Database Update: Game state is updated in MongoDB
- Real-time Broadcast: WebSocket broadcasts updates to all connected clients
- Winner Selection: After cooldown period, winner is randomly selected on-chain
- Reward Claim: Winner claims the jackpot via smart contract
- Node.js >= 16.x
- Yarn or npm
- Rust >= 1.70.0 (for smart contract development)
- Solana CLI >= 1.16.0
- Anchor CLI >= 0.28.0
- MongoDB >= 5.0 (local or cloud instance)
- Solana Wallet (Phantom, Solflare, etc.)
git clone https://github.com/mooncitydev/solana-jackpot-game.git
cd solana-jackpot-gamecd Jackpot_backend
yarn install
# or
npm installcd ../Jackpot_frontend
yarn install
# or
npm installcd ../Jackpot_program/jackpot
yarn install
anchor buildCreate Jackpot_backend/.env:
PORT=3002
CORS_ORIGIN=*
SOLANA_NETWORK=devnet
SOLANA_MAINNET=https://api.mainnet-beta.solana.com
SOLANA_DEVNET=https://api.devnet.solana.com
PROGRAM_ID=E13jNxzoQbUuyaZ9rYJUdRAirYZKU75NJNRV9CHdDhHE
DB_CONNECTION=mongodb://localhost:27017/jackpotCreate Jackpot_frontend/.env.local:
NEXT_PUBLIC_API_URL=http://localhost:3002
NEXT_PUBLIC_SOCKET_URL=http://localhost:3002
NEXT_PUBLIC_NETWORK=devnet
NEXT_PUBLIC_RPC_URL=https://api.devnet.solana.com
NEXT_PUBLIC_PROGRAM_ID=E13jNxzoQbUuyaZ9rYJUdRAirYZKU75NJNRV9CHdDhHE
NEXT_PUBLIC_CREATOR_ADDRESS=A8rgsJecHutEamvb7e8p1a14LQH3vGRPr796CDaESMeu
NEXT_PUBLIC_SOL_PRICE_API=https://api.coingecko.com/api/v3/simple/price?ids=solana&vs_currencies=usdMake sure MongoDB is running locally or update DB_CONNECTION with your cloud MongoDB URI.
For development, you can use the existing program ID or deploy your own:
cd Jackpot_program/jackpot
anchor build
anchor deploy --provider.cluster devnet- PORT: Server port (default: 3002)
- CORS_ORIGIN: Allowed CORS origins
- SOLANA_NETWORK:
devnetormainnet - PROGRAM_ID: Your deployed program ID
- DB_CONNECTION: MongoDB connection string
- NEXT_PUBLIC_API_URL: Backend API URL
- NEXT_PUBLIC_SOCKET_URL: WebSocket server URL
- NEXT_PUBLIC_NETWORK: Solana network (
devnetormainnet) - NEXT_PUBLIC_RPC_URL: Solana RPC endpoint
- NEXT_PUBLIC_PROGRAM_ID: Smart contract program ID
cd Jackpot_backend
yarn dev
# or
npm run devServer will start on http://localhost:3002
cd Jackpot_frontend
yarn dev
# or
npm run devFrontend will start on http://localhost:3000
Backend:
cd Jackpot_backend
yarn build
yarn startFrontend:
cd Jackpot_frontend
yarn build
yarn startsolana-jackpot-game/
├── Jackpot_backend/ # Backend server
│ ├── src/
│ │ ├── index.ts # Express server & routes
│ │ ├── script.ts # Solana transaction processing
│ │ ├── db.ts # Database operations
│ │ ├── jackpot.ts # Anchor IDL types
│ │ ├── model/ # Mongoose models
│ │ └── config.ts # Configuration constants
│ ├── package.json
│ └── tsconfig.json
│
├── Jackpot_frontend/ # Next.js frontend
│ ├── src/
│ │ ├── pages/ # Next.js pages
│ │ ├── components/ # React components
│ │ ├── context/ # React context providers
│ │ ├── utils/ # Utility functions
│ │ └── styles/ # Global styles
│ ├── public/ # Static assets
│ ├── package.json
│ └── next.config.js
│
└── Jackpot_program/ # Solana smart contract
└── jackpot/
├── programs/
│ └── jackpot/
│ └── src/
│ └── lib.rs # Main program logic
├── tests/ # Anchor tests
├── Anchor.toml
└── Cargo.toml
- initialize: Initialize the vault account
- playGame: Create a new game pool and deposit initial amount
- enterGame: Join an existing game pool
- claimReward: Winner claims the jackpot
- First player calls
playGameto create a new game - Additional players call
enterGameto join - After cooldown period, admin calls
claimReward - Winner is selected based on random number and deposit amounts
- Winner receives entire jackpot
Winner selection uses a deterministic random number derived from:
- On-chain timestamp
- Program-derived address (PDA)
- Character multiplication of address
Note: For production, consider using Switchboard or Chainlink VRF for more secure randomness.
GET /health- Health checkGET /getMessage- Get recent chat messagesPOST /writeMessage- Send a chat messageGET /getRecentGame- Get current game statePOST /createGame- Process game creation transactionPOST /enterGame- Process game entry transaction
Client → Server:
- Connection automatically established
Server → Client:
connectionUpdated- Active connection countchatUpdated- New chat messagestartGame- New game startedendTimeUpdated- Game end time updatedgameEnded- Game finished, winner announcednewGameReady- New game available
This project is intended as a proof of concept. Before deploying to mainnet:
- ✅ Use Secure Randomness: Implement Switchboard or Chainlink VRF
- ✅ Smart Contract Audit: Get professional security audit
- ✅ Rate Limiting: Add anti-bot and rate limiting protections
- ✅ Input Validation: Validate all user inputs
- ✅ Access Control: Implement proper admin controls
- ✅ Error Handling: Comprehensive error handling and logging
- ✅ Testing: Extensive unit and integration tests
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Telegram: @moooncity
For questions, support, or collaboration opportunities, feel free to reach out via Telegram.