Inspiration

The idea for Blockchain Battle Arena came from a desire to create a truly decentralized game where all logic lives on-chain, not just NFTs or tokens. We were inspired by classic turn-based fighting games but wanted to leverage blockchain's transparency and immutability to ensure fair combat where no player can cheat or manipulate outcomes. The challenge: could we build an engaging, real-time multiplayer experience entirely on Ethereum?

What it does

Blockchain Battle Arena is a fully on-chain PvP combat game where:

  • Players deposit 0.001 ETH to enter matchmaking via the GameConsole smart contract
  • Two players are paired and a new PlayGround contract instance is deployed for their battle
  • Each battle consists of 5 rounds with 30-second move selection phases
  • Players strategically choose 5 moves per round: positioning (up/down) and attacks (basic/medium/special)
  • Damage is calculated based on lane positioning and attack timing using pure on-chain logic
  • The winner receives 0.0015 ETH and the platform takes a 0.0005 ETH fee
  • All game state and moves are permanently stored on the blockchain for transparency

How we built it

Smart Contract Architecture:

  • Built with Solidity ^0.8.0 using Foundry as the development framework
  • GameConsole.sol: Handles matchmaking, emits MatchFound events, manages the player queue
  • PlayGround.sol: Individual game instance with 5-round combat logic, damage calculation formulas, and prize distribution
  • Implemented attack exhaustion system: Basic (3 uses), Medium (2 uses), Special (1 use) that auto-converts to "stay" when depleted

Frontend Development:

  • Next.js 15 with TypeScript for type safety and modern React patterns
  • wagmi v2 and viem for seamless Web3 integration
  • DaisyUI + TailwindCSS for clean, responsive UI components
  • Real-time timer synchronized with contract timing: 10s waiting phase + 30s move selection
  • Auto-refresh mechanism: refetch() every 3 seconds to update game state without page reloads
  • Side-by-side player panels showing health, attack counts, and move history

Backend Automation:

  • Node.js service with ethers.js v6 for contract interaction
  • Listens to MatchFound events to track active games
  • Monitors games every 5 seconds and calls calculateResult() from the owner's account when time expires
  • Ensures rounds progress even if players don't manually trigger calculation

Challenges we ran into

  1. Timer Synchronization: Getting the frontend timer to perfectly align with moveSelectionStartTime, moveSelectionDuration, and waitDuration from the contract was tricky. We had to refetch timing variables on every update and implement immediate timer recalculation when moveSelectionStartTime changed.

  2. Attack Exhaustion Logic: Implementing attack tracking across 5 moves per round while auto-converting exhausted attacks to "stay" required careful state management. We used uint8[5] arrays to track remaining attacks and validate them during PerformMoves().

  3. Payment Flow: Initially, prize distribution and entry fees weren't flowing correctly. We had to ensure GameConsole collected 0.001 ETH from each player and sent exactly 0.002 ETH to the PlayGround constructor as {value: 0.002 ether}.

  4. Backend Automation: Figuring out how to trigger calculateResult() from the owner's account without requiring player interaction was challenging. We solved this with an event-driven backend service that monitors contract events.

  5. False "Time's Up" Display: The timer showed "Time's Up!" during the 10-second waiting phase. Fixed by adding !isWaitingPhase check to the isTimeUp condition.

Accomplishments that we're proud of

Fully Decentralized Game Logic: Every battle rule, damage calculation, and outcome is determined by smart contracts—no centralized server can manipulate results.

Real-time UX: Achieved smooth real-time updates with auto-refresh every 3 seconds, eliminating jarring page reloads.

Attack Exhaustion System: Successfully implemented limited-use attacks that automatically convert to defensive moves when depleted across all 5 moves.

Event-driven Architecture: Backend service elegantly handles round calculations using MatchFound and timing checks without manual player triggers.

Complete Game Loop: From matchmaking → combat → prize distribution → game cleanup, the entire flow works seamlessly.

Production-ready Codebase: Zero ESLint errors, comprehensive README documentation, and clean Git history pushed to GitHub.

What we learned

Smart Contract Design:

  • How to use payable constructors to initialize contracts with ETH
  • Event emission patterns for off-chain monitoring (MatchFound, RoundCalculated)
  • Making functions public vs external for different access patterns

Frontend-Contract Synchronization:

  • Using wagmi's refetch() methods to update data without page reloads
  • Timer synchronization with blockchain timestamps using block.timestamp
  • Handling contract read errors gracefully when data isn't available yet

Backend Automation:

  • Event-driven architecture with ethers.js contract.on() listeners
  • Interval-based monitoring patterns for time-dependent contract logic
  • Managing wallet instances for automated transaction signing

Development Workflow:

  • Using ESLint and Husky for code quality enforcement
  • Git workflow with meaningful commit messages and proper remote setup
  • Documentation-driven development with comprehensive README files

What's next for Blockchain Battle Arena

🎯 Multiple Concurrent Games: Scale the platform to support hundreds of simultaneous battles

🏆 Leaderboard System: Track win/loss records, ELO ratings, and global rankings

⚔️ Ranked Matchmaking: Match players based on skill level for balanced gameplay

🖼️ NFT Rewards: Award unique NFT badges for achievements, win streaks, and tournament victories

📹 Replay System: Store move history on IPFS and allow players to replay past battles

📱 Mobile Optimization: Responsive design improvements for mobile gameplay

🌐 Mainnet Deployment: Deploy to Ethereum mainnet or L2 solutions (Arbitrum, Optimism) for lower gas fees

🎮 Character Classes: Introduce different fighter types with unique abilities and stats

💬 In-game Chat: Add encrypted messaging for trash talk and GG's

🏅 Tournament Mode: Organize bracket-style competitions with larger prize pools


Built With

Share this project:

Updates