On-chain Rock-Paper-Scissors battles with Pyth randomness & PYUSD betting
RPS Arena is a decentralized Rock-Paper-Scissors battle game built on Ethereum that combines verifiable randomness with instant payouts. Players see a battlefield scenario with Rock/Paper/Scissors units, predict the winner, place their bet in PYUSD or ETH, and watch the epic battle unfold with on-chain randomness from Pyth Network.
The game features: Instant gameplay: Players place bets and get results immediately using Pyth's verifiable randomness Multi-token support: Bet with ETH or PYUSD with configurable minimums Fair randomness: Uses Pyth Entropy V2 for provably fair game outcomes Battle animations: Canvas-based visual battles with real-time results Solvency protection: Smart contract reserves funds to guarantee payouts Commission system: Built-in house edge with withdrawable profits
Built on scaffold-eth framework with Hardhat 3 for smart contract development and Next.js for the frontend. The project leverages several cutting-edge technologies:
Smart Contract Architecture: Pyth Entropy V2 integration for verifiable randomness with customizable gas limits Multi-token support with ERC20 token management and fee-on-transfer handling Solvency protection with real-time liability tracking and maximum bet calculations Reentrancy guards and comprehensive error handling for security
Frontend Stack: Next.js 14 with App Router for modern React development Wagmi + RainbowKit for seamless wallet integration Canvas API for battle animations and visual effects TypeScript throughout for type safety
Key Technical Innovations: Entropy callback system: Asynchronous randomness generation with sequence number tracking Dynamic solvency: Real-time calculation of maximum bet amounts based on contract balance Token abstraction: Unified interface for ETH and ERC20 tokens with different decimal handling Gas optimization: Custom entropy gas limits and efficient state management Notable hacks: Fee-on-transfer token support: Measures actual received amounts vs. requested amounts Sequence number mapping: Bidirectional mapping between entropy requests and game IDs Timeout mechanism: Admin can expire stuck games and refund players Commission separation: Tracks house profits separately from player funds The project demonstrates advanced smart contract patterns while maintaining a simple, engaging user experience that makes blockchain gaming accessible to mainstream users.

