Application 3: Mempool Duel

First and foremost, the demo and the github repo. I would truly appreciate any feedback, so donโ€™t hold back ; )

A little disclaimer, Iโ€™ve never really built a game and this is my first attempt at building one. I was not able to make the frontend work in time, but the contract is deployed and working.

Current Deployment Status โœ…

Base Sepolia Testnet (Chain ID: 84532)

  • Contract Address: 0xF0Fb1a485571Db8475A1271C6f7f47b695e51971

  • Blocklock Sender: 0x82Fed730CbdeC5A2D8724F2e3b316a70A565e27e

  • Deployment Block: 30023696

  • Transaction Hash: 0x36f54706e398d6da62d88c007066a125a04276c971a750d039575fe9478d6d02

  • Verification: โœ… Verified on Basescan

  • Gas Used: 2,398,063 gas

  • Cost: 0.000002398202087654 ETH

Contract Parameters

  • Min Wager: 0.001 ETH (1,000,000,000,000,000 wei)

  • Max Wager: 1 ETH (1,000,000,000,000,000,000 wei)

  • Timeout Blocks: 100 blocks

Game Concept

Mempool Duel is a quick, high-stakes, two-player web game based on the classic "Rock, Paper, Scissors" logic. It's designed for fast rounds of play where fairness is cryptographically guaranteed. The game is framed as a conflict between two rival data couriers in a cyberpunk universe, settling their disputes through a quick, decisive digital duel.

Game Story

In the neon-drenched metropolis of Neo-Kyoto, information is the most valuable currency. Rival data couriers, known as "Runners," constantly vie for supremacy on the digital frontier. When two Runners cross paths with conflicting contracts, disputes are settled not with weapons, but with code. Mempool Duel is the digital arena where these conflicts are resolvedโ€”a lightning-fast game of strategy where a single move can determine the outcome. Victory requires anticipating your opponent's logic, but the system's integrity is absolute, ensuring no Runner can cheat the code.

Gameplay Mechanics

  1. The Wager: Two players connect their wallets to the game's smart contract. To initiate a duel, they each place a small, equal wager (e.g., 1 MATIC, 5 USDC) into the contract, which holds the total pot in escrow.

  2. The Choice: Both players are simultaneously presented with three choices for their move:

    • ICE (Rock): A brute-force defensive program.

    • Spike (Paper): A sharp, invasive script that bypasses defenses.

    • Glitch (Scissors): A disruptive code snippet that corrupts invasive scripts. (The classic rules apply: ICE breaks Glitch, Glitch corrupts Spike, Spike bypasses ICE).

  3. The Blocklock Commit: Once a player selects their move, the game's front-end uses blocklock-js to encrypt their choice. The decryption condition is set to a targetBlock just a few blocks into the future (e.g., current block + 3) to ensure a rapid game resolution.

  4. The Duel: Each player submits their single, encrypted transaction to the game's smart contract. The blockchain records that both players have submitted their moves, but the moves themselves remain completely secret and unreadable.

  5. The Reveal & Resolution: When the targetBlock is reached, the dcipher network automatically delivers the decryption keys for both moves to the smart contract. The contract instantly executes a resolveDuel function which:

    • Decrypts both moves simultaneously.

    • Determines the winner based on the game's logic.

    • Automatically transfers the entire pot to the winner's wallet.

    • In the event of a draw (e.g., both choose ICE), the wagers are automatically returned to each player.

How Blocklock Solves the Fairness Problem

Blocklock's primary role in Mempool Duel is to solve the fundamental challenge of fairness in on-chain games of simultaneous choice.

  • The Problem with Transparency: On a public blockchain, all pending transactions are visible in a "waiting room" called the mempool. Without encryption, if Player 1 submits their move "ICE," Player 2 could see this pending transaction and simply submit the winning counter-move, "Spike," with a higher fee to ensure their transaction is processed first. This is a form of front-running that makes a fair game impossible.

  • The Old Solution (Commit-Reveal): The traditional way to solve this was a two-step "commit-reveal" scheme. Players would first submit a hash of their move (the "commit"), and then, in a second transaction, submit the actual move (the "reveal"). While this works, it has significant drawbacks:

    • Poor User Experience: It requires each player to make two separate transactions, which is inconvenient and doubles the gas fees.

    • Reveal Dependency: The game can stall or fail if a player decides not to submit their reveal transaction, especially if they anticipate losing.

  • The Blocklock Advantage: Blocklock provides an elegant, single-step solution. By encrypting the move, it achieves both "commit" and "reveal" in one action.

    • Hiding: The move is completely hidden from the opponent while in the mempool, preventing any front-running attacks.

    • Binding: Once the transaction is submitted, the move cannot be changed.

    • Automated Reveal: The reveal is handled automatically and simultaneously for both players by the smart contract when the time condition is met. This removes the dependency on players to submit a second transaction.

This makes Mempool Duel a provably fair mini-game where victory is determined by strategy and psychology, not by who has the fastest connection or the most technical skill at monitoring the blockchain.

๐Ÿš€ Features

๐ŸŽฎ Core Gameplay

  • Three Strategic Moves: ICE (Rock), Spike (Paper), Glitch (Scissors)

  • Cryptographic Fairness: Time-locked encryption prevents cheating

  • Instant Resolution: Automatic decryption and payout when conditions are met

  • Wager System: Place bets in MATIC, USDC, or other supported tokens

๐Ÿ” Security & Transparency

  • Blocklock Encryption: Uses dcipher network for time-locked encryption

  • Smart Contract Escrow: Automated wager holding and payout

  • On-Chain Verification: All game results are publicly verifiable

  • No Front-Running: Encrypted moves prevent manipulation

๐ŸŽจ User Experience

  • Pixel-Art Aesthetic: Retro gaming style with modern blockchain functionality

  • Responsive Design: Works seamlessly on desktop and mobile devices

  • Real-Time Updates: Live game status and blockchain confirmation

  • Wallet Integration: Seamless MetaMask and other wallet connections

๐Ÿ› ๏ธ Technology Stack

Frontend

  • Next.js 13 - React framework with App Router

  • TypeScript - Type-safe development

  • Tailwind CSS - Utility-first CSS framework

  • Wagmi - React hooks for Ethereum

  • Ethers.js - Ethereum library

Blockchain

  • Solidity - Smart contract development

  • Hardhat - Development environment

  • Blocklock-js - Time-locked encryption

  • dcipher Network - Decentralized encryption infrastructure

Networks Supported

  • Base Sepolia (Testnet) - Primary development network

  • Polygon Mumbai (Testnet) - Alternative testnet

  • Ethereum Sepolia (Testnet) - Ethereum testnet

๐Ÿ“‹ Prerequisites

Before you begin, ensure you have the following:

  • Node.js (v16 or later)

  • npm (v7 or later) or yarn

  • MetaMask or compatible Web3 wallet

  • Test tokens for your chosen network

  • Basic knowledge of blockchain and Web3 concepts

๐Ÿš€ Quick Start

1. Clone the Repository

git clone https://github.com/yourusername/mempool-duel.git
cd mempool-duel

2. Install Dependencies

npm install
# or
yarn install

3. Environment Setup

Create a .env.local file in the root directory:

# Network RPC URLs
NEXT_PUBLIC_BASE_SEPOLIA_RPC_URL=https://sepolia.base.org
NEXT_PUBLIC_POLYGON_MUMBAI_RPC_URL=https://rpc-mumbai.maticvigil.com

# Contract Addresses (Base Sepolia - Deployed)
NEXT_PUBLIC_MEMPOOL_DUEL_CONTRACT=0xF0Fb1a485571Db8475A1271C6f7f47b695e51971
NEXT_PUBLIC_BLOCKLOCK_SENDER=0x82Fed730CbdeC5A2D8724F2e3b316a70A565e27e

4. Start Development Server

npm run dev
# or
yarn dev

Open http://localhost:3000 in your browser to see the application.

5. Test the Deployed Contract ๐Ÿงช

The contract is already deployed on Base Sepolia testnet! To test it:

  1. Switch to Base Sepolia in your wallet

  2. Get test ETH from the faucet links above

  3. Connect your wallet to the game

  4. Create a duel with 0.001 ETH wager

  5. Test the game flow with another player

๐ŸŽฏ How to Play

1. Connect Your Wallet

  • Click "Connect Wallet" and authorize your Web3 wallet

  • Ensure you're on a supported network (Base Sepolia recommended)

  • Have test tokens ready for wagers

2. Join or Create a Duel

  • Quick Duel: Get matched automatically with another player

  • Create Duel: Set your own wager amount and wait for challengers

  • Join Duel: Accept an existing challenge from the Duel Board

3. Make Your Move

  • Choose from three strategic options:

    • ICE ๐ŸงŠ: Defensive program (beats Glitch)

    • Spike โšก: Invasive script (beats ICE)

    • Glitch ๐Ÿ’€: Corruptive code (beats Spike)

  • Your choice is encrypted and committed to the blockchain

4. Wait for Resolution

  • Both players' moves remain encrypted until the target block

  • The dcipher network automatically delivers decryption keys

  • Smart contract resolves the duel and distributes winnings

5. Claim Your Victory

  • Winners automatically receive the entire pot

  • Draws result in wager returns to both players

  • All results are verifiable on-chain

๐Ÿ—๏ธ Project Structure

mempool-duel/
โ”œโ”€โ”€ app/                          # Next.js App Router
โ”‚   โ”œโ”€โ”€ globals.css              # Global styles and pixel-art theme
โ”‚   โ”œโ”€โ”€ layout.tsx               # Root layout component
โ”‚   โ””โ”€โ”€ page.tsx                 # Main entry point
โ”œโ”€โ”€ components/                   # React components
โ”‚   โ””โ”€โ”€ mempool-duel/           # Game-specific components
โ”‚       โ”œโ”€โ”€ Header.tsx          # Game header with wallet connection
โ”‚       โ”œโ”€โ”€ GameHub.tsx         # Main game hub and navigation
โ”‚       โ”œโ”€โ”€ CreateDuelPanel.tsx # Duel creation interface
โ”‚       โ”œโ”€โ”€ DuelBoard.tsx       # List of open duels
โ”‚       โ”œโ”€โ”€ GameArena.tsx       # Main game interface
โ”‚       โ”œโ”€โ”€ MoveSelector.tsx    # Move selection component
โ”‚       โ”œโ”€โ”€ WaitingPhase.tsx    # Encryption waiting period
โ”‚       โ””โ”€โ”€ GameResult.tsx      # Game outcome display
โ”œโ”€โ”€ hooks/                       # Custom React hooks
โ”‚   โ””โ”€โ”€ useMempoolDuel.ts      # Game logic and blockchain interactions
โ”œโ”€โ”€ lib/                         # Utility libraries
โ”‚   โ”œโ”€โ”€ contract.ts             # Contract ABIs and addresses
โ”‚   โ””โ”€โ”€ mempoolDuelContract.ts  # Simplified contract interface
โ”œโ”€โ”€ public/                      # Static assets
โ”‚   โ””โ”€โ”€ cyberpunk-icon.svg      # Game icon
โ””โ”€โ”€ README.md                    # This file

๐Ÿ”ง Configuration

Network Configuration

The game supports multiple networks with automatic detection:

// Supported networks and their configurations
const CHAIN_ID_TO_ADDRESS = {
  "84532": "0xF0Fb1a485571Db8475A1271C6f7f47b695e51971", // Base Sepolia (Deployed)
  "80001": "0x...", // Polygon Mumbai
  "11155111": "0x..." // Ethereum Sepolia
};

Contract Deployment

To deploy your own contracts:

  1. Compile Contracts

     npx hardhat compile
    
  2. Deploy to Network

     npx hardhat run scripts/deploy.js --network baseSepolia
    
  3. Update Environment Variables Update .env.local with your deployed contract addresses

Current Deployment Status โœ…

Base Sepolia Testnet (Chain ID: 84532)

  • Contract Address: 0xF0Fb1a485571Db8475A1271C6f7f47b695e51971

  • Blocklock Sender: 0x82Fed730CbdeC5A2D8724F2e3b316a70A565e27e

  • Deployment Block: 30023696

  • Transaction Hash: 0x36f54706e398d6da62d88c007066a125a04276c971a750d039575fe9478d6d02

  • Verification: โœ… Verified on Basescan

  • Gas Used: 2,398,063 gas

  • Cost: 0.000002398202087654 ETH

Contract Parameters

  • Min Wager: 0.001 ETH (1,000,000,000,000,000 wei)

  • Max Wager: 1 ETH (1,000,000,000,000,000,000 wei)

  • Timeout Blocks: 100 blocks

๐Ÿงช Testing

Run Tests

npm run test
# or
yarn test

Test on Testnet

  1. Ensure you have test tokens (Base Sepolia ETH)

  2. Connect to Base Sepolia (Chain ID: 84532) - Recommended for testing

  3. Create a test duel with minimal wager (0.001 ETH minimum)

  4. Test the complete game flow

Getting Base Sepolia Testnet ETH

๐Ÿš€ Deployment

npm run build
vercel --prod

Other Platforms

The app can be deployed to any platform that supports Next.js:

  • Netlify

  • AWS Amplify

  • DigitalOcean App Platform

  • Self-hosted servers

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Workflow

  1. Fork the repository

  2. Create a feature branch (git checkout -b feature/amazing-feature)

  3. Commit your changes (git commit -m 'Add amazing feature')

  4. Push to the branch (git push origin feature/amazing-feature)

  5. Open a Pull Request

๐Ÿ“„ License

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

๐Ÿ™ Acknowledgments

  • dcipher Network - For providing the blocklock encryption infrastructure

  • Base Network - For testnet support and development resources

  • Ethereum Community - For the foundation of decentralized applications

  • Open Source Contributors - For the tools and libraries that make this possible

๐Ÿ“ž Support

๐Ÿ”ฎ Roadmap

Phase 1: Core Gameplay โœ…

  • Basic game mechanics

  • Smart contract integration

  • Wallet connection

  • Pixel-art UI theme

Phase 2: Enhanced Features ๐Ÿšง

  • Tournament system

  • Leaderboards

  • NFT rewards

  • Mobile app

Phase 3: Advanced Features ๐Ÿ“‹

  • Cross-chain support

  • Social features

  • Advanced betting options

  • API for third-party integrations


Ready to duel? Connect your wallet and enter the arena! ๐ŸŽฎโšก

Built with โค๏ธ by the Mempool Duel team

0
Subscribe to my newsletter

Read articles from Mohammad Hatif Osmani directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mohammad Hatif Osmani
Mohammad Hatif Osmani

A passionate software developer who loves experimenting and learning new tech.