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.