← Back to home

RogueChain

RogueChain: Infinite on-chain roguelike. Dungeons procedurally generated by Pyth Entropy.

Problem Statement

RogueChain is a revolutionary Web3 RPG game that combines NFT technology with real-time oracle data to create dynamic, market-adaptive gameplay. Players mint unique Hero NFTs and battle in dungeons where difficulty and rewards change based on live ETH/BTC price feeds from Pyth Network.🚀 Key Features: • Real-time market integration (ETH/USD, BTC/USD price feeds) • Dynamic market states (BEAR/NORMAL/BULL/EXTREME) affecting gameplay • ERC721 Hero NFTs with randomized stats and level progression • Production-ready frontend with MetaMask integration • Live on Optimism Sepolia with gas-optimized transactions🌐 Live Demo: https://rogue-chain.vercel.app/ 📧 Contract: 0x01b4b5227A1234A32b23bdBCF63C354f1253C963Built with Solidity 0.8.28, Pyth Network SDK, Ethers.js, and modern Web3 best practices. Demonstrates advanced oracle integration, security-first smart contract design, and seamless user experience.

Solution

RogueChain is built as a full-stack Web3 application, leveraging a robust Solidity smart contract on Optimism Sepolia and an interactive frontend.Smart Contract (Backend Logic):The core game logic resides in theRogueChain.solsmart contract, developed withSolidity 0.8.28. It utilizesHardhatfor development, testing, and deployment. Key components include:OpenZeppelin Contracts:ERC721,ERC721Enumerable,Ownable, andReentrancyGuardare used to manage Hero NFTs, ensure ownership, and prevent re-entrancy attacks.Pyth Network Integration: We integrate directly withPyth Network's Price Feeds(for ETH/USD and BTC/USD) andPyth Entropyfor randomness. This enables dynamic market-based gameplay and secure, verifiable randomness for dungeon outcomes. The contract includes custom interfaces (IPythEntropyCallback) to handle Pyth's pull-based oracle model.Deployment: The contract is deployed on theOptimism Sepoliatestnet usingHardhat Ignition, ensuring a streamlined and reliable deployment process.Frontend (User Interface):The user-friendly interface is built with standard web technologies:HTML5 & CSS3: For structuring and styling a modern, responsive, and app-like user experience, with a focus on mobile-first design.JavaScript: Powers all interactive elements and blockchain interactions.Ethers.js: Used for connecting to MetaMask, interacting with the deployedRogueChainsmart contract, and handling transactions.Manual Pyth Hermes API Integration: Due to challenges with direct Pyth EVM JS SDK integration in the browser environment, we implemented a customfetch-based solution to retrieve real-time price update data from thePyth Hermes API. This data is then passed to the smart contract for on-chain price verification.How They're Pieced Together:The frontend communicates with the smart contract viaEthers.js, using the contract's ABI (frontend/abi.json) and address. When a user initiates an action (e.g., "Mint Hero" or "Enter Dungeon"), the frontend constructs a transaction, fetches necessary off-chain data (like Pyth price updates from Hermes), and prompts the user to sign it via MetaMask. The smart contract then processes the transaction, updates its state, and emits events. The frontend listens for these events to update the UI in real-time, providing immediate feedback on hero stats, dungeon results, and market changes.Notable & "Hacky" Aspects:Dynamic Pyth Integration: The project dynamically fetches Pyth price update data from the Hermes API in the frontend and passes it to the smart contract. This ensures that the on-chain market state and victory chances are influenced by the latest real-world price data.Client-Side Fallback for Complex Contract Logic: To ensure a smooth user experience and prevent reverts from complex on-chain calculations (likegetMarketState()andcalculateVictoryChance()), the frontend currently uses simplified client-side logic for displaying market status and victory chances. This was a pragmatic decision to maintain a "working system" for the hackathon, while the contract's full Pyth integration is robustly handled for critical functions likeupdatePriceFeeds.Robust Error Handling: Extensivetry-catchblocks are implemented both in Solidity and JavaScript to gracefully handle potential issues with Pyth oracle updates, network interactions, and transaction failures, providing clear feedback to the user.

Hackathon

ETHOnline 2025

2025

Contributors