Skip to content

Trivia-app-x/Frontend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

TriviaChain - Decentralized Trivia Game ๐ŸŽฎ

โš ๏ธ DEVELOPMENT STATUS: MVP IN PROGRESS This is an early-stage MVP under active development. Backend functionality is currently being built. The smart contract is deployed on Arbitrum Sepolia testnet.

A blockchain-based multiplayer trivia game built on Arbitrum Stylus, leveraging Web3 technologies for real-time, trustless gaming experiences.

๐Ÿ“‹ Table of Contents

๐ŸŽฏ About

TriviaChain is a decentralized trivia game where players can create or join game sessions, compete in real-time, and have their scores recorded on-chain. The game leverages Arbitrum Stylus smart contracts written in Rust for efficient, low-cost blockchain interactions.

โœจ Features

Current (MVP)

  • โœ… Wallet Connection: Connect with MetaMask, Rainbow, and other Web3 wallets via RainbowKit
  • โœ… Create Game Sessions: Host games with customizable settings (max players, question count, difficulty)
  • โœ… Join Game Sessions: Join games using unique room codes
  • โœ… Game Lobby: Real-time player tracking before game starts
  • โœ… Multiple Question Categories: Tech, General Knowledge, and Party questions
  • โœ… Difficulty Levels: Easy, Medium, and Hard questions with varying time limits
  • โœ… On-chain Score Recording: Player scores stored on Arbitrum blockchain
  • โœ… Winner Determination: Smart contract determines and records winners

Planned Features

  • ๐Ÿ”„ Backend Integration: Real-time game synchronization
  • ๐Ÿ”„ Leaderboards: Global and session-based rankings
  • ๐Ÿ”„ NFT Rewards: Winner badges and achievements as NFTs
  • ๐Ÿ”„ Custom Question Pools: Allow users to create custom trivia sets
  • ๐Ÿ”„ Spectator Mode: Watch ongoing games
  • ๐Ÿ”„ Tournament Mode: Multi-round elimination tournaments

๐Ÿ›  Tech Stack

Frontend

  • React 19 - UI framework
  • TypeScript - Type safety
  • Vite - Build tool and dev server
  • TailwindCSS - Styling
  • Wagmi - Ethereum interactions
  • Viem - Ethereum utilities
  • RainbowKit - Wallet connection UI
  • React Hot Toast - Notifications

Blockchain

  • Arbitrum Stylus - Layer 2 smart contract platform
  • Rust - Smart contract language (backend contract)
  • Arbitrum Sepolia - Testnet deployment

๐Ÿ“ฆ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v18 or higher)
  • npm or yarn or pnpm
  • Git
  • MetaMask or another Web3 wallet browser extension

๐Ÿš€ Getting Started

1. Clone the Repository

git clone <repository-url>
cd trivia-app/Frontend

2. Install Dependencies

npm install
# or
yarn install
# or
pnpm install

3. Environment Setup

Create a .env file in the root directory:

cp .env.example .env

Edit .env with your configuration:

VITE_WALLETCONNECT_PROJECT_ID=your_walletconnect_project_id
VITE_TRIVIA_CONTRACT_ADDRESS=0xb619a20ace8e373752c960347f96805434129e89

Get your WalletConnect Project ID:

  1. Go to WalletConnect Cloud
  2. Create a new project
  3. Copy your Project ID

4. Add Arbitrum Sepolia to Your Wallet

Network Details:

  • Network Name: Arbitrum Sepolia
  • RPC URL: https://sepolia-rollup.arbitrum.io/rpc
  • Chain ID: 421614
  • Currency Symbol: ETH
  • Block Explorer: https://sepolia.arbiscan.io/

Get Testnet ETH:

5. Run Development Server

npm run dev

The app will be available at http://localhost:5173

6. Build for Production

npm run build

Preview production build:

npm run preview

๐ŸŒ Environment Setup

Required Environment Variables

Variable Description Required
VITE_WALLETCONNECT_PROJECT_ID WalletConnect Cloud project ID Yes
VITE_TRIVIA_CONTRACT_ADDRESS Deployed smart contract address Yes

Network Configuration

The app is configured to work with Arbitrum Sepolia testnet. Configuration can be found in src/wagmi.ts.

๐Ÿ“ Smart Contract

Contract Details

  • Address: 0xb619a20ace8e373752c960347f96805434129e89
  • Network: Arbitrum Sepolia
  • Language: Rust (Stylus)
  • Block Explorer: View on Arbiscan

Key Contract Functions

// Create a new game session
createSession(room_code: bytes32, max_players: uint256, question_duration: uint256) -> uint256

// Join an existing session
joinSession(session_id: uint256, room_code: bytes32, display_name: bytes32)

// Start the game (host only)
startSession(session_id: uint256)

// Submit an answer
submitAnswer(session_id: uint256, question_index: uint256, answer_hash: bytes32, correct_answer_hash: bytes32, difficulty: uint8) -> uint256

// End game and determine winner
endSession(session_id: uint256) -> address

// Get winner address
getWinner(session_id: uint256) -> address

// Get player score
getPlayerScore(session_id: uint256, player: address) -> uint256

Contract Events

  • SessionCreated - Emitted when a new game is created
  • PlayerJoined - Emitted when a player joins
  • SessionStarted - Emitted when host starts the game
  • AnswerSubmitted - Emitted when a player submits an answer
  • SessionEnded - Emitted when game ends with winner info

๐Ÿ“ Project Structure

Frontend/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ components/           # React components
โ”‚   โ”‚   โ”œโ”€โ”€ HomePage.tsx      # Landing page with wallet connection
โ”‚   โ”‚   โ”œโ”€โ”€ HostGame.tsx      # Create game interface
โ”‚   โ”‚   โ”œโ”€โ”€ JoinGame.tsx      # Join game interface
โ”‚   โ”‚   โ”œโ”€โ”€ GameLobby.tsx     # Pre-game lobby
โ”‚   โ”‚   โ”œโ”€โ”€ GamePlay.tsx      # Main game interface
โ”‚   โ”‚   โ””โ”€โ”€ GameResults.tsx   # Post-game results
โ”‚   โ”œโ”€โ”€ contracts/
โ”‚   โ”‚   โ””โ”€โ”€ TriviaChain.ts    # Contract ABI and address
โ”‚   โ”œโ”€โ”€ data/
โ”‚   โ”‚   โ””โ”€โ”€ questions.ts      # Question pool
โ”‚   โ”œโ”€โ”€ types/
โ”‚   โ”‚   โ””โ”€โ”€ index.ts          # TypeScript types
โ”‚   โ”œโ”€โ”€ App.tsx               # Main app component
โ”‚   โ”œโ”€โ”€ main.tsx              # App entry point
โ”‚   โ”œโ”€โ”€ wagmi.ts              # Wagmi configuration
โ”‚   โ””โ”€โ”€ index.css             # Global styles
โ”œโ”€โ”€ public/                   # Static assets
โ”œโ”€โ”€ .env.example              # Environment template
โ”œโ”€โ”€ package.json              # Dependencies
โ”œโ”€โ”€ vite.config.ts            # Vite configuration
โ”œโ”€โ”€ tailwind.config.js        # Tailwind configuration
โ””โ”€โ”€ tsconfig.json             # TypeScript configuration

๐ŸŽฎ Game Flow

1. Connect Wallet

  • User connects Web3 wallet via RainbowKit
  • Supports MetaMask, Rainbow, WalletConnect, and more

2. Host or Join Game

Host:

  • Set max players (2-10)
  • Choose question count (5-20)
  • Select difficulty (Easy/Medium/Hard/Mixed)
  • Choose category (Tech/General/Party/Mixed)
  • Receive unique 6-character room code

Join:

  • Enter 6-character room code
  • Provide display name

3. Game Lobby

  • Wait for players to join
  • Host can see all connected players
  • Host starts game when ready

4. Gameplay

  • Questions displayed one at a time
  • Time-limited answers (15-30s based on difficulty)
  • Points awarded based on:
    • Correctness
    • Speed of answer
    • Question difficulty
  • Progress tracked on-chain

5. Results

  • Winner determined by smart contract
  • Final scores displayed
  • Option to play again

๐Ÿ—บ Development Roadmap

Phase 1: MVP (Current) โœ…

  • Frontend UI/UX
  • Wallet integration
  • Smart contract integration
  • Basic game flow
  • Question system

Phase 2: Backend & Real-time (In Progress) ๐Ÿ”„

  • WebSocket server for real-time sync
  • Backend API for game state management
  • Database for game history
  • Improved player synchronization

Phase 3: Enhanced Features ๐Ÿ“‹

  • Leaderboards and statistics
  • NFT reward system
  • Custom question pools
  • Tournament mode
  • Spectator mode
  • Social features (friend challenges, chat)

Phase 4: Scaling & Optimization ๐Ÿš€

  • Performance optimization
  • Multi-chain support
  • Mobile app (React Native)
  • Advanced analytics
  • Community governance

๐Ÿค Contributing

Contributions are welcome! This is an active development project.

Development Guidelines

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Style

  • Use TypeScript for type safety
  • Follow React best practices
  • Use Tailwind CSS for styling
  • Write meaningful commit messages
  • Comment complex logic

๐Ÿ› Known Issues

  • Backend synchronization not implemented (frontend-only MVP)
  • Real-time player updates rely on blockchain events (may have delays)
  • Question pool is limited (hardcoded)
  • No persistence of game history

๐Ÿ“„ License

This project is part of the Web3Bridge Rust Masterclass program.

๐Ÿ”— Links

๐Ÿ“ง Support

For questions or issues, please open an issue in the repository.


Built with โค๏ธ for Web3Bridge Rust Masterclass

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages