Skip to content

AntrikshRawat/wordChain

Repository files navigation

WordChain India

A blockchain-based competitive word game built on React Native, Ethereum smart contracts, and The Graph protocol. Players compete in timed word chain races where the fastest solver wins the prize pool.

🎮 Overview

WordChain India is a decentralized gaming platform that combines:

  • Real-time competitive gameplay - Players race to solve word chain puzzles
  • Blockchain-based wagering - Entry fees create prize pools managed by smart contracts
  • Automated game orchestration - Backend scheduler manages game sessions
  • Decentralized data indexing - The Graph subgraph for efficient querying

🏗️ Architecture

Frontend

  • Framework: React Native with Expo
  • Navigation: React Navigation (Stack + Bottom Tabs)
  • Web3 Integration: ethers.js v6
  • UI Components: Custom screens for Lobby, Game Arena, Leaderboard, Profile, and Wallet

Backend

  • Server: Express.js
  • Game Logic: Automated scheduler with cron jobs
  • Blockchain Integration: ethers.js for smart contract interaction
  • Dictionary Management: Word validation service

Smart Contracts

  • WagerQuest.sol - Core game contract managing entry fees, scoring, and prize distribution
  • QuestFactory.sol - Factory pattern for deploying new game instances
  • RewardPool.sol - Prize pool management
  • MockMONToken.sol - Test token for development

Subgraph

  • Protocol: The Graph
  • Schema: Game and Player entities
  • Indexing: Real-time blockchain event tracking

📁 Project Structure

wordChain/
├── App.js                    # Main app entry with navigation
├── index.js                  # Expo entry point
├── package.json              # Root dependencies
│
├── screens/                  # React Native screens
│   ├── LobbyScreen.js        # Game listing & join
│   ├── GameArenaScreen.js    # Active gameplay
│   ├── LeaderboardScreen.js  # Rankings & stats
│   ├── ProfileScreen.js      # User profile
│   └── WalletScreen.js       # Web3 wallet integration
│
├── components/
│   └── ErrorBoundary.js      # Error handling wrapper
│
├── services/
│   └── web3.js               # Blockchain interaction layer
│
├── backend/                  # Express server
│   ├── server.js             # Server entry point
│   └── src/
│       ├── config.js         # Environment configuration
│       ├── routes.js         # API endpoints
│       ├── scheduler.js      # Cron job management
│       ├── dictionary.js     # Word validation
│       └── services/
│           ├── gamestate.js  # Game session management
│           └── blockchain.js # Smart contract integration
│
├── contracts/                # Solidity smart contracts
│   ├── hardhat.config.js     # Hardhat configuration
│   ├── contracts/
│   │   ├── WagerQuest.sol    # Main game contract
│   │   ├── QuestFactory.sol  # Game factory
│   │   ├── RewardPool.sol    # Prize distribution
│   │   └── MockMONToken.sol  # Test token
│   ├── scripts/
│   │   └── deploy.js         # Deployment script
│   └── artifacts/            # Compiled contracts
│
└── subgraph/                 # The Graph indexing
    ├── schema.graphql        # GraphQL schema
    ├── subgraph.yaml         # Subgraph manifest
    ├── src/
    │   └── mapping.ts        # Event handlers
    └── generated/            # Auto-generated types

🚀 Getting Started

Prerequisites

  • Node.js (v16+)
  • npm or yarn
  • Expo CLI
  • Hardhat (for smart contracts)
  • MetaMask or compatible Web3 wallet

Installation

  1. Clone the repository
git clone <repository-url>
cd wordChain
  1. Install root dependencies
npm install
  1. Install backend dependencies
cd backend
npm install
cd ..
  1. Install contract dependencies
cd contracts
npm install
cd ..
  1. Install subgraph dependencies
cd subgraph
npm install
cd ..

Environment Setup

Create a .env file in the root directory:

# Backend
PORT=3000

# Blockchain
PRIVATE_KEY=your_private_key_here
RPC_URL=your_rpc_url_here
CONTRACT_ADDRESS=deployed_contract_address

# Game Configuration
GAME_DURATION=3600
ENTRY_FEE=0.01

Development

Run the entire application

npm run dev

This concurrently starts:

  • Expo development server (React Native app)
  • Express backend server

Run components separately

Frontend only

npm start
# or
npm run android  # For Android
npm run ios      # For iOS
npm run web      # For web browser

Backend only

npm run server

Smart Contract Deployment

  1. Compile contracts
cd contracts
npx hardhat compile
  1. Deploy to network
npx hardhat run scripts/deploy.js --network <network-name>
  1. Update contract addresses in backend configuration

Subgraph Deployment

  1. Generate types
cd subgraph
npm run codegen
  1. Build subgraph
npm run build
  1. Deploy to The Graph
graph deploy --studio <subgraph-name>

🎯 Core Features

Game Mechanics

  • Timed Races: Players compete to solve word chains within a fixed time window
  • Entry Fees: Players pay to join, creating a prize pool
  • King of the Hill: Fastest solver becomes current leader
  • Prize Distribution: 90% to winner, 10% platform fee

Smart Contract Functions

WagerQuest.sol

  • joinGame() - Pay entry fee and join the active game
  • recordPlayerResult(address) - Oracle function to record completion time (admin only)
  • finalizeGame() - Distribute prizes after game ends

API Endpoints

GET /game-status

Returns current game state, timer, and prize pool

POST /submit-guess

Submit word guess for validation

{
  "userAddress": "0x...",
  "guess": "yourword"
}

POST /start-game

Admin endpoint to manually trigger a new game session

🔧 Technology Stack

Layer Technology
Frontend React Native, Expo, React Navigation
Backend Node.js, Express.js
Smart Contracts Solidity, Hardhat, OpenZeppelin
Blockchain Ethereum (EVM-compatible)
Web3 Library ethers.js v6
Indexing The Graph Protocol
Scheduling node-cron
Development Concurrently

📱 Screens

  1. Lobby - Browse and join active games
  2. Game Arena - Full-screen word chain gameplay
  3. Leaderboard - Global rankings and statistics
  4. Profile - User stats and game history
  5. Wallet - Web3 wallet integration and balance

🔐 Security Features

  • Entry validation prevents duplicate joins
  • Time-locked prize distribution
  • Admin-only oracle pattern for result recording
  • OpenZeppelin contracts for security standards
  • Error boundaries for graceful frontend failures

📊 Data Flow

  1. Game Creation: Scheduler deploys new WagerQuest contract via QuestFactory
  2. Player Join: User pays entry fee via mobile app → Smart contract
  3. Gameplay: User submits guess → Backend validates → Records on-chain
  4. Completion: Backend detects winner → Calls recordPlayerResult()
  5. Finalization: After timer expires → finalizeGame() distributes prizes
  6. Indexing: Subgraph indexes all events for frontend queries

🧪 Testing

# Test smart contracts
cd contracts
npx hardhat test

# Test backend
cd backend
npm test

📄 License

This project is licensed under the ISC License.

👥 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a pull request

🐛 Known Issues

  • Ensure all environment variables are properly configured
  • Contract addresses must be updated after deployment
  • Expo development requires network connectivity

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors