Defi Duels

Crypto battle cards with Pyth Entropy randomness and real-time price-boosted stats ⚔️🃏

Defi Duels

Created At

ETHGlobal New Delhi

Project Description

DUEL is a decentralized card battle game that revolutionizes blockchain gaming by integrating Pyth Network's cutting-edge infrastructure. Players collect and battle with 16 unique crypto-themed cards (like "Vitalik" the ETH Wizard and "Sato Nako" the BTC Knight), where deck generation uses Pyth Entropy for cryptographically secure randomness - ensuring completely fair and unpredictable card distribution that can't be manipulated.

The game's standout innovation is its real-time price integration system. Each card is linked to actual cryptocurrency price feeds from Pyth Network, so when Bitcoin surges 5%, the BTC-themed card gets a 5% attack boost in battles. Players can engage in Quick Battles against AI or stake ETH in winner-takes-all battles against other players, with card performance dynamically adjusted based on live crypto market movements.

Built with a gas-optimized smart contract and intuitive web interface, DUEL offers free-to-start gameplay (5 unlock tickets for new players) while demonstrating how decentralized oracles can create engaging, transparent gaming experiences. The project showcases the first practical combination of Pyth Entropy and Price Feeds, bridging traditional card game mechanics with the excitement of cryptocurrency markets in a completely trustless environment.

How it's Made

Smart Contract & Pyth Integration Built the core game logic in Solidity using Hardhat, integrating directly with Pyth's Entropy and Price Feed contracts. For deck generation, I implemented an asynchronous callback pattern where the contract requests entropy from Pyth, receives cryptographically secure random bytes, and generates 5 unique card IDs. The trickiest part was handling Pyth's price data normalization - each feed uses different exponents, so I built a dual API system fetching current prices from Hermes and historical data from Benchmarks, then calculating price = rawPrice * 10^exponent with retry logic for inconsistent endpoints.

Frontend Engineering & Real-time Price Boosts The frontend uses vanilla JavaScript with Ethers.js v6, featuring a real-time price boost system that fetches 24-hour changes for all 16 cryptocurrencies in parallel when battles start, applying percentage changes as attack multipliers to corresponding cards. I implemented several notable hacks: packed card metadata in frontend constants instead of expensive on-chain storage, event-driven UI updates to reduce RPC calls, and a mock mode toggle using localStorage that simulates all blockchain interactions for seamless testing. The most challenging aspect was synchronizing three async data sources (smart contract state, Pyth entropy callbacks, and live price feeds) into a responsive user experience despite blockchain latency.

background image mobile

Join the mailing list

Get the latest news and updates