
Dice-Prediction-Game-chainlink-vrf
A decentralized game
Demo
About
The problem it solves Traditional online gambling and prediction games are often: ❌ Opaque – Users can’t verify if outcomes are fair or manipulated. ❌ Centralized – Results and funds are controlled by a single entity. ❌ Limited trust – Players must blindly trust the platform’s backend logic. ❌ Lacking transparency – No way to prove the randomness of outcomes. ✅ How This Game Fixes That 🎲 Trustless Dice Rolls Every dice roll is powered by Chainlink VRF, ensuring provable randomness that no one can tamper with—not even the developers. 🛡️ Transparent Game Logic Smart contracts are public and auditable, letting users verify the entire flow—from predictions to payouts. 💸 Instant, Fair Rewards Winnings are distributed automatically by the smart contract based on the outcome—no middlemen, no delays. 🌍 Open Access Anyone with a wallet can play. No sign-ups, no KYC, just pure decentralized fun.
How it's made
Challenges we ran into 1. Integrating Chainlink VRF Seamlessly Problem: Calling Chainlink VRF in a prediction-based flow was tricky, especially handling the asynchronous nature of randomness fulfillment. Solution: Refactored the game logic to wait for fulfillRandomWords before determining outcomes. Used mapping of request IDs to player data to track who triggered what. ⚠️ 2. Handling Race Conditions Problem: Users could trigger multiple games at once, causing unexpected behavior or overlapping state changes. Solution: Added game state locks per player using mappings to ensure a user can only play one round at a time. 🎭 3. UI Not Reflecting On-Chain Events Instantly Problem: Frontend wasn’t updating after a dice roll until page refresh. Solution: Subscribed to contract events via Ethers.js to listen for GameResult events and trigger UI updates in real-time. 📦 4. Chainlink VRF Setup on Testnets Problem: Getting the VRF subscription and coordinator contracts set up correctly on testnets was confusing at first. Solution: Followed Chainlink’s docs, used their faucet to fund the subscription, and debugged using Foundry logs and Hardhat traces to verify randomness requests.