RogueChain

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

RogueChain

Created At

ETHOnline 2025

Project Description

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: 0x01b4b5227A1234A32b23bdBCF63C354f1253C963

Built 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.

How it's Made

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 the RogueChain.sol smart contract, developed with Solidity 0.8.28. It utilizes Hardhat for development, testing, and deployment. Key components include:

  • OpenZeppelin Contracts: ERC721, ERC721Enumerable, Ownable, and ReentrancyGuard are used to manage Hero NFTs, ensure ownership, and prevent re-entrancy attacks.
  • Pyth Network Integration: We integrate directly with Pyth Network's Price Feeds (for ETH/USD and BTC/USD) and Pyth Entropy for 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 the Optimism Sepolia testnet using Hardhat 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 deployed RogueChain smart 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 custom fetch-based solution to retrieve real-time price update data from the Pyth 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 via Ethers.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 (like getMarketState() and calculateVictoryChance()), 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 like updatePriceFeeds.
  • Robust Error Handling: Extensive try-catch blocks 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.
background image mobile

Join the mailing list

Get the latest news and updates