Skip to content

deeps00007/color-prediction-chain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

107 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License Solidity Network Status Node



🎰 Color Prediction Chain

A decentralized multi-game platform powered by Ethereum smart contracts

Play fully on-chain with Color Game Tokens (CGT) via our new Game Dashboard.


🕹️ Games Available

1. Color Prediction

Bet Color Game Tokens (CGT) on RED, GREEN, or VIOLET.

  • RED/GREEN: 2x Multiplier
  • VIOLET: 5x Multiplier (High Risk, High Reward)

2. Plinko

Drop the ball down the peg pyramid. Watch it bounce into prize slots ranging from 0.2x to 1000x.


▶ PLAY LIVE NOW



🌐 Live Deployment

The game is live on Sepolia Testnet. Play right now — no installation required.

Component Link Status
🎮 Frontend color-prediction-chain.vercel.app 🟢 Online
⚙️ Backend color-prediction-chain.onrender.com 🟢 Online
🪙 Game Token (CGT) 0xfDf4...7fe7A 🟢 Active
📜 Color Contract 0x982A...1dD6 🟢 Active
🔻 Plinko Contract 0xbFE1...55fD 🟢 Active

📱 Mobile App

The game is also available as a Flutter mobile app with full WalletConnect integration.

Features

  • WalletConnect v2: Connect securely with MetaMask or other mobile wallets
  • Deep Linking: Seamless redirection back to the app after signing transactions
  • Real-time Updates: Live game rounds and history
  • Native Experience: Smooth performance on Android & iOS

Getting Started

Prerequisites

  • Flutter SDK installed
  • An Android Emulator or physical device

Installation

  1. Navigate to the mobile directory:

    cd game-mobile
  2. Install dependencies:

    flutter pub get
  3. Run the app:

    flutter run

Usage

  1. Tap the Wallet icon in the top right.
  2. Select MetaMask (or your preferred wallet).
  3. Approve the connection in your wallet app.
  4. The app will automatically reopen via the colorprediction:// deep link scheme.

Dev Note: The deep link scheme is configured in android/app/src/main/AndroidManifest.xml. If you change it, remember to update the redirectUrl in WalletService.dart.


🎮 How to Play

⏱️ Takes about 1 minute to start playing.

Step 1 — Connect Your Wallet

Click "Connect Wallet" on the game page. MetaMask will ask you to switch to the Sepolia Testnet and add a high-speed RPC endpoint. Approve both.

Step 2 — Get Gas (Free Sepolia ETH)

You need a tiny amount of ETH to pay for gas fees on transactions. Use one of these faucets to get it for free:

Faucet Link Amount
Google Cloud (Fastest) cloud.google.com/…/sepolia 0.01 ETH
Alchemy alchemy.com/faucets 0.05 ETH
QuickNode faucet.quicknode.com 0.05 ETH

💡 Tip: Click your wallet address in the top-left corner of the game to copy it instantly.

Step 3 — Mint Game Tokens

Click "🪙 Mint 1000 CGT" in the game. Confirm the MetaMask transaction. You now have 1,000 free Color Game Tokens to bet with.

Step 4 — Play the Games

Navigate to the Dashboard and choose your game.

Option A: Color Prediction 🔴🟢🟣

  1. Pick a color:
    • RED or GREEN (2x Payout)
    • VIOLET (5x Payout)
  2. Enter bet amount (e.g., 10 CGT).
  3. Click "Place Bet".
  4. Winnings are sent automatically when the round ends (~30s).

Option B: Plinko 🔻

  1. Set the risk level by choosing Rows (8, 12, or 16).
    • More rows = Higher potential multiplier (up to 1000x).
  2. Enter bet amount.
  3. Click "Play" to drop a ball.
  4. Winnings are distributed instantly based on the slot the ball lands in.

⚡ Features

Feature Description
🪙 Custom ERC-20 Token Bets use Color Game Token (CGT) — no real money at risk
🔓 Public Minting Anyone can mint tokens freely to play
🎮 Multi-Game Support Switch between Color Prediction and Plinko
🤖 Automated Rounds (Color Game) Backend resolves every round every 30 seconds
📡 Robust RPC Load-balanced public RPCs prevent rate-limiting
📊 Real-time History Supabase tracks every round result live
⛓️ Trustless Payouts Smart contract pays winners directly — no manual approval

🏗️ Architecture

┌─────────────┐   Bets    ┌──────────────────┐   Pays    ┌──────────────┐
│             │  Tokens   │  Smart Contract   │  Tokens   │              │
│   User /    │──────────>│   (The House)     │──────────>│   Winner's   │
│  Frontend   │           │                   │           │   Wallet     │
│             │           │  placeBet()       │           │              │
└──────┬──────┘           │  resolveRound()   │           └──────────────┘
       │                  └────────┬──────────┘
       │                           │
       │ Views History             │ Resolves Round
       ▼                           ▼
┌─────────────┐           ┌──────────────────┐
│  Supabase   │<──────────│  Game Backend    │
│     DB      │  Updates  │   (The Brain)    │
│             │   Stats   │  30s Round Timer │
└─────────────┘           └──────────────────┘

Data Flow:

  1. User places bet → Frontend calls placeBet() → Tokens locked in contract
  2. 30 seconds pass → Backend detects round end → Generates result
  3. Backend calls resolveRound() → Contract pays all winners instantly
  4. Backend logs result → Supabase updated → Frontend shows live history

🛠️ Tech Stack

Layer Technology
⛓️ Blockchain Ethereum — Sepolia Testnet
📜 Smart Contracts Solidity 0.8.20 + OpenZeppelin (ERC-20)
🔧 Dev Framework Hardhat
🌐 Frontend HTML, CSS, JavaScript, ethers.js, React, Vite
📱 Mobile Flutter (Dart), WalletConnect v2
🤖 Backend Node.js, Express
🗄️ Database Supabase (PostgreSQL)
🦊 Wallet MetaMask

📂 Project Structure

color-prediction-chain/
│
├── contracts/
│   ├── ColorPrediction.sol       # Main game logic (bets, payouts, rounds)
│   └── GameToken.sol             # ERC-20 token contract (CGT)
│
├── game-frontend/
│   ├── index.html                # Game UI
│   ├── src/                      # React components & logic
│   └── vite.config.js            # Build configuration
│
├── game-mobile/
│   ├── lib/                      # Flutter source code
│   ├── android/                  # Android native configuration
│   └── pubspec.yaml              # Dart dependencies
│
├── game-backend/
│   ├── index.js                  # Express server entry point
│   ├── roundEngine.js            # Core game loop (30s timer + resolution)
│   ├── supabaseClient.js         # Supabase connection
│   ├── .env                      # Config (never committed!)
│   └── package.json
│
├── scripts/
│   └── deploy.js                 # Deploys GameToken + ColorPrediction + funds house
│
├── hardhat.config.js             # Hardhat network configuration
├── START_ALL.bat                 # One-click local launcher (Windows)
├── .gitignore                    # Excludes .env, node_modules, artifacts
└── README.md                     # This file

💻 Local Development

Want to run this on your own machine? Follow these steps.

1. Clone the Repository

git clone https://github.com/deeps00007/color-prediction-chain.git
cd color-prediction-chain

2. Install Dependencies

npm install
cd game-backend && npm install && cd ..

3. Start the Local Environment

Windows:

START_ALL.bat

This automatically:

  • ✅ Starts a local Hardhat blockchain
  • ✅ Deploys both contracts (GameToken + ColorPrediction)
  • ✅ Funds the house with 50,000 CGT
  • ✅ Starts the game backend

4. Play Locally

  1. Open game-frontend/index.html in your browser
  2. Switch MetaMask to Localhost 8545 network
  3. Import a Hardhat test account (copy private key from the Hardhat terminal)
  4. Mint tokens and start betting

⚙️ Configuration

All settings live in game-backend/.env:

# Blockchain
RPC_URL=http://127.0.0.1:8545                          # Local development
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/...  # Sepolia testnet
PRIVATE_KEY=0x...                                       # Deployer wallet key

# Contracts (updated after deployment)
CONTRACT_ADDRESS=0x...
TOKEN_ADDRESS=0x...

# Game
ROUND_DURATION_SECONDS=30

# Database
SUPABASE_URL=https://...
SUPABASE_SERVICE_KEY=eyJ...

🔧 Troubleshooting

Problem Solution
"Transaction reverted" Reset MetaMask activity: Settings → Advanced → Clear Activity Tab Data
Balance shows 0 CGT Click "Mint 1000 CGT" and confirm in MetaMask
Rounds not progressing Check that the backend server is running and .env has correct addresses
"Insufficient funds" for gas Get free Sepolia ETH from a faucet (see How to Play)
Contract shows empty Fund the house: npx hardhat run scripts/deploy.js --network localhost
Can't connect wallet Make sure MetaMask is unlocked and you're on the correct network

🛡️ Security Notice

This is a Testnet / Educational project. Be aware of the following:

Limitation Details
🎲 Centralized Randomness Results are generated by the backend, not Chainlink VRF
🪙 Infinite Minting Anyone can mint unlimited CGT tokens
🏗️ No Audit This contract has not been professionally audited

⚠️ Do not use real-value assets with this contract.

For production, these would need to be addressed: integrate Chainlink VRF for verifiable randomness, remove public minting, add a professional security audit, and implement emergency pause mechanisms.


🤝 Contributing

Contributions are welcome!


📜 License

This project is licensed under the MIT License. See the LICENSE file for details.


Built with by Deepanshu Singh

About

Blockchain color prediction game: Bet test ETH on RED/GREEN/VIOLET, get instant payouts from smart contracts. Built with Solidity, Hardhat, Node.js & Supabase. Auto-resolves every 30 seconds. Educational demo showcasing trustless payments on Ethereum.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors