project screenshot 1
project screenshot 2
project screenshot 3
project screenshot 4
project screenshot 5
project screenshot 6

KingOfWeb3Knowledge

put your web 3 knowledge to test, competing against AI and other ppl!

KingOfWeb3Knowledge

Created At

ETHGlobal Taipei

Winner of

World

World - World Pool Prize

Prize Pool

Project Description

Project Overview

At its core, the project is an engaging quiz game where users answer multiple-choice questions. The game is enhanced with Web3 features such as authentication, payment, and verification using WorldCoin’s MiniKit. Users can sign in via a WorldCoin-based OAuth provider, participate in the game, and even perform blockchain-based payments or verifications—all within a responsive, dynamic interface.


Key Technologies & Architecture

  • Next.js & React: The application leverages Next.js for server-side rendering, routing, and API endpoint creation. The UI is built with React components, using functional components and hooks for state management and effects.
  • TypeScript: Code is type-checked for reliability and better developer experience.
  • Tailwind CSS: Styling is primarily handled with Tailwind CSS along with some custom CSS, ensuring a responsive and modern design.
  • WorldCoin MiniKit Integration: The project integrates WorldCoin’s MiniKit to facilitate:
    • Authentication: Users can sign in using a WorldCoin OAuth provider integrated with NextAuth.
    • Payment: The app supports initiating and confirming payments using blockchain tokens.
    • Verification: Users can verify their identity or actions via cryptographic proofs processed through WorldCoin’s verification endpoints.
  • NextAuth: Provides session management and authentication flows. It supports multiple providers, with WorldCoin as the key authentication provider.
  • Eruda: A debugging console (integrated conditionally in non-production environments) to assist with client-side debugging during development.

Detailed Components & Functionality

1. Layout and Global Styling

  • layout.tsx: Establishes the global structure of the app. It wraps children components with providers such as NextAuthProvider, MiniKitProvider, and conditionally, an Eruda debugging console.
  • globals.css: Contains base styles and Tailwind directives, along with CSS custom properties for theming (supporting dark mode).

2. Authentication Flow

  • NextAuth Provider: Configured in /api/auth/[...nextauth]/route.ts, it integrates a WorldCoin OAuth provider and handles sign-in callbacks.
  • SignIn Component: Provides a simple UI to sign in (or sign out) using NextAuth. It listens for session changes to update the application state.

3. Quiz Game Mechanics

  • Game Module: The game (located under ./Game/modules/Game.tsx) randomly selects a set of questions from a JSON data file.
    • Game Logic: Manages state for player and opponent scores, question progress, timer countdown, and answer selections.
    • Scoring: Based on how quickly a correct answer is provided, using a decreasing exponential function to calculate scores.
  • UI Components:
    • Question: Displays the current question text.
    • AnswerOptions: Renders available answer buttons with visual feedback (e.g., correct/wrong highlights and icons).
    • Timer: A countdown component that has been enhanced to include a progress bar that visually shrinks as time runs out. When only a few seconds remain, the progress bar shakes and displays a bomb emoji to heighten urgency.

4. Enhanced Timer Component

  • The timer has been transformed into a progress bar that reacts to time pressure:
    • Visual Feedback: As the timer counts down, the progress bar width decreases. When time is critically low (e.g., 3 seconds or less), it shakes to simulate a bomb about to go off.
    • User Engagement: The bomb emoji and shaking effect create a sense of urgency, enhancing the user experience during the quiz.

5. WorldCoin MiniKit Integration

  • Payment Flow:
    • Initiation: The /api/initiate-payment/route.ts endpoint generates a unique payment nonce, stored in cookies.
    • Confirmation: The /api/confirm-payment/route.ts endpoint verifies that the received transaction matches the initiated payment by comparing the nonce and checking the transaction status via WorldCoin’s API.
    • UI Component (PayBlock): Invokes the MiniKit pay command and processes the response, displaying success or failure messages.
  • Verification Flow:
    • Backend Verification: The /api/verify/route.ts endpoint accepts a payload from MiniKit’s verification command, verifies the cryptographic proof using WorldCoin’s verifyCloudProof method, and returns a success or error status.
    • Frontend Integration: The VerifyBlock component initiates the verification process and displays the result, enabling developers to handle user verification seamlessly.

Additional Aspects

  • Dynamic Imports & Client-Side Only Components: Certain components (e.g., Eruda and MiniKit integrations) are dynamically imported to ensure they run only on the client side, preserving server-side rendering capabilities.
  • State & Animation: The game uses React state hooks and CSS animations (for shaking effects) to provide a lively and interactive user experience.
  • Debugging & Development: Eruda integration helps developers debug the client-side behavior without impacting the production experience.

How it's Made

1. Frontend Architecture

  • Next.js & React:
    The project leverages Next.js for its powerful routing and server-side rendering capabilities. React functional components, along with hooks (like useState and useEffect), manage the dynamic UI and state.

  • Global Layout & Providers:
    The RootLayout component (in layout.tsx) wraps all pages with multiple providers:

    • NextAuthProvider: Integrates NextAuth for authentication.
    • MiniKitProvider: Installs the WorldCoin MiniKit on the client side, enabling blockchain-based features.
    • ErudaProvider: Conditionally loads a client-side debugging tool (Eruda) during development.
  • Styling:
    Styling is achieved using Tailwind CSS along with custom global styles in globals.css and component-specific styles in dedicated CSS files. The project supports dark mode by adjusting CSS custom properties.

  • Interactive Game UI:
    The quiz game is composed of several modular components:

    • Game Module:
      Manages the overall game state, randomly selects a set of questions from a JSON file, tracks scores, and handles transitions between questions.
    • Question & AnswerOptions Components:
      Render the current question and multiple-choice answers. These components provide immediate visual feedback on selection, using CSS classes to indicate correct and incorrect responses.
    • Enhanced Timer Component:
      Reimagined as a progress bar that shrinks as time decreases. When time gets critically low (e.g., 3 seconds or less), the timer adds a shaking animation and bomb emoji to create a sense of urgency.

2. Backend API & Serverless Functions

  • API Routes with Next.js:
    The application defines several API endpoints using Next.js’s serverless functions:
    • Authentication (/api/auth/[...nextauth]/route.ts):
      Utilizes NextAuth for secure user authentication, integrating WorldCoin as an OAuth provider.
    • Payment Flow:
      • Initiate Payment (/api/initiate-payment/route.ts):
        Generates a unique payment nonce (stored in a cookie) to track the transaction.
      • Confirm Payment (/api/confirm-payment/route.ts):
        Verifies that the payment details received from the MiniKit match the initiated transaction by checking the nonce and querying the WorldCoin API.
    • Verification (/api/verify/route.ts):
      Handles the verification process by receiving a cryptographic proof from the client, using WorldCoin’s verifyCloudProof function to validate the payload before confirming the verification status.

3. WorldCoin MiniKit Integration

  • Authentication & Verification:
    The integration with WorldCoin MiniKit enables:
    • User Authentication: Allowing users to sign in using their WorldCoin credentials.
    • Verification: Users can verify their identity or actions through cryptographic proofs. The frontend component VerifyBlock initiates this process and sends the proof to the backend for confirmation.
  • Blockchain Payment:
    The project implements a payment flow:
    • Initiating a Payment: A unique transaction reference is created and stored, ensuring that the payment process can be tracked.
    • Payment Command Execution: The PayBlock component triggers the MiniKit payment command, allowing the user to send tokens. The backend then verifies the transaction status to confirm payment success.

4. Interactive & Dynamic User Experience

  • State Management & Animations:
    React state and side effects are used to handle game dynamics, such as tracking the time left on the timer and updating scores in real time. CSS animations (like the shaking effect on the timer when time is nearly up) add a layer of interactivity that enhances user engagement.

  • Responsive Design:
    The combination of Tailwind CSS and custom styling ensures the application is responsive, providing an optimal experience across different devices and screen sizes.

  • Debugging Tools:
    Tools like Eruda are integrated conditionally to help developers debug the application in development environments without affecting production.

background image mobile

Join the mailing list

Get the latest news and updates