A decentralized coinflip casino game built on the Solana . Players can bet SOL on coin flips (heads or tails) with a 50/50 chance to win double their bet amount.
- BX51pEVZAgWqxvgrPfX9yDiiU4WTKs4PZT34M5MjCRuc
- Simple Coinflip Game: Bet on heads or tails with a 50/50 chance
- SOL Betting: Bet using Solana's native SOL token
- Modern UI: Beautiful, responsive interface with dark/light mode
- Secure: Built on Solana blockchain with smart contract security
- Game History: View recent games and transaction history
- Instant Rewards: Win 2x your bet amount (plus fee refund)
- Fair Play: Transparent random number generation using blockchain data
casino-coinflip-game/
βββ fe/ # Frontend (Next.js + TypeScript)
β βββ src/
β β βββ components/ # React components
β β βββ contexts/ # Blockchain interactions & utilities
β β βββ pages/ # Next.js pages
β β βββ styles/ # SCSS stylesheets
β β βββ idl/ # Anchor IDL files
β βββ package.json
β
βββ sc/ # Smart Contract (Anchor + Rust)
β βββ programs/
β β βββ coinflip/ # Main Solana program
β βββ tests/ # Test files
β βββ migrations/ # Deployment scripts
β βββ Anchor.toml # Anchor configuration
β
βββ README.md
- Framework: Next.js 12.1.0
- Language: TypeScript
- UI: Material-UI, Custom SCSS
- Wallet: Solana Wallet Adapter
- Blockchain: @solana/web3.js, @project-serum/anchor
- Framework: Anchor 0.31.1
- Language: Rust
- Network: Solana Devnet/Mainnet
Before you begin, ensure you have the following installed:
- Node.js (v16 or higher)
- Yarn or npm
- Rust (latest stable version)
- Solana CLI (v1.18.0 or higher)
- Anchor CLI (v0.31.1)
- Git
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
avm install latest
avm use latestgit clone <repository-url>
cd casino-coinflip-gamecd sc
# Install dependencies
yarn install
# Build the program
anchor build
# Run tests
anchor test
# Deploy to devnet (make sure your wallet is configured)
anchor deployNote: Update Anchor.toml with your program ID and wallet path before deploying.
cd fe
# Install dependencies
npm install
# Start development server
npm run devThe frontend will be available at http://localhost:3000
After deploying the smart contract, update the program ID in:
fe/src/contexts/type.ts- UpdatePROGRAM_IDfe/src/idl/coinflip.json- Update with new IDL (copy fromsc/target/idl/coinflip.json)
Edit sc/Anchor.toml:
[programs.devnet]
coinflip = "YOUR_PROGRAM_ID"
[provider]
cluster = "devnet" # or "mainnet"
wallet = "~/.config/solana/id.json"Edit fe/src/contexts/type.ts:
export const PROGRAM_ID = new PublicKey("YOUR_PROGRAM_ID");
export const NETWORK = "devnet"; // or "mainnet"-
Connect Wallet: Click the wallet button and connect your Solana wallet (Phantom, Solflare, etc.)
-
Enter Bet Amount: Input your desired bet amount in SOL
-
Flip Coin: Click "FLIP COIN" button (the game randomly selects heads or tails)
-
Wait for Result: The coin will flip and show the result
-
Win or Lose:
- Win: You receive 2x your bet amount (plus fee refund)
- Lose: You lose your bet amount and fee
-
Claim Rewards: Click the claim button to withdraw your winnings
- PDA (Program Derived Address): Vault uses PDAs for secure fund storage
- Admin Controls: Only authorized admin can update settings
- Balance Validation: Checks sufficient balance before allowing bets
- Vault Validation: Ensures vault has enough funds for payouts
- Random Generation: Uses blockchain timestamp and slot for randomness
- Minimum bet: Defined in smart contract constants
- Maximum bet: Limited by vault balance
- Fee: 4% of bet amount (configurable by admin)
- Win multiplier: 2x bet amount + fee refund
The game uses blockchain data (timestamp + slot) to generate random results, ensuring fairness and transparency.
- Winners receive:
bet_amount * 2 + fee - Losers lose:
bet_amount + fee - Fee goes to loyalty wallet
cd sc
anchor testcd fe
npm run devcd sc
# Build
anchor build
# Deploy to devnet
anchor deploy --provider.cluster devnet
# Deploy to mainnet (be careful!)
anchor deploy --provider.cluster mainnetcd fe
# Build for production
npm run build
# Start production server
npm run startOr deploy to platforms like:
- Vercel: Connect your GitHub repo
- Netlify: Use the Netlify plugin
- Any static hosting: Upload the
outfolder afternpm run build
cd sc
# Build
anchor build
# Test
anchor test
# View logs
solana logscd fe
# Development server with hot reload
npm run dev
# Build
npm run build
# Lint
npm run lint- Program ID:
BX51pEVZAgWqxvgrPfX9yDiiU4WTKs4PZT34M5MjCRuc(Devnet) - Network: Solana Devnet (configurable)
-
"Program ID mismatch"
- Update
PROGRAM_IDinfe/src/contexts/type.ts - Update IDL in
fe/src/idl/coinflip.json
- Update
-
"Insufficient funds"
- Ensure your wallet has enough SOL for transaction fees
- Check vault balance for rewards
-
"Global state not initialized"
- Run the initialization function (admin only)
- Check that the global pool account exists
-
Build errors
- Ensure Rust and Anchor versions match
- Run
anchor cleanand rebuild
- See
INDEX.mdfor detailed project documentation - See
fe/README.mdfor frontend-specific docs - See
sc/README.mdfor smart contract docs
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.
This is a gambling application. Please gamble responsibly. The developers are not responsible for any losses incurred while using this application.
- Solana Foundation
- Anchor Framework
- Solana Wallet Adapter Team
For issues and questions:
- Open an issue on GitHub
- Check existing documentation in
INDEX.md
Built with me on Solana
