Mon Aug 11 2025


Lottery - Decentralized Raffle System
Solidity
Ethereum
Chainlink VRF
Chainlink Automation
Foundry
Decentralized Raffle is a provably fair lottery system built on Ethereum, leveraging Chainlink VRF for secure randomness and Chainlink Automation for automated winner selection.
What is Decentralized Raffle?
Introduction
Decentralized Raffle is a blockchain-based lottery system built on Ethereum, designed to provide a transparent and provably fair experience for participants. By integrating Chainlink VRF v2 for cryptographically secure random number generation and Chainlink Automation for automated execution, this project ensures trustless winner selection without manual intervention. Deployed using Foundry, the smart contract offers robust security features and a seamless user experience for entering raffles and claiming prizes.
Features
- Provably Fair Randomness: Utilizes Chainlink VRF v2 to generate cryptographically secure random numbers, ensuring unbiased winner selection with on-chain verifiable proof.
- Automated Execution: Chainlink Automation triggers raffle completion based on time intervals, eliminating the need for manual intervention.
- Transparent Prize Pool: All entrance fees are collected in the contract, and the entire balance is awarded to the winner.
- Secure State Management:
- Two states:
OPEN
(accepting entries) andCALCULATING
(processing winner). - Prevents entries during winner calculation for integrity.
- Two states:
- User-Friendly Interaction:
- Simple entry process with a fixed entrance fee.
- Events emitted for raffle entry and winner selection for easy tracking.
- Robust Security:
- Reentrancy protection through state updates before external calls.
- Custom error handling for clear failure reporting.
- Gas-optimized design with immutable variables.
- Testing and Coverage: Comprehensive test suite using Foundry, covering key functionalities like entry, upkeep, and winner selection.
User Workflow
- Users connect their Ethereum wallet (e.g., MetaMask) to the raffle frontend.
- Users pay the entrance fee in ETH to enter the raffle via the
enterRaffle()
function. - Chainlink Automation monitors the contract and triggers
performUpkeep()
when the raffle interval elapses and conditions are met. - Chainlink VRF generates a random number, and the contract selects a winner via
fulfillRandomWords()
. - The prize pool is automatically transferred to the winner’s address.
- Users can view the recent winner, raffle state, and participant list through the frontend.
- The raffle resets automatically for the next round.
Tech Stack
- Solidity ^0.8.18: Smart contract development for Ethereum.
- Foundry: Development framework for testing, deployment, and coverage analysis.
- Chainlink VRF v2: Provides verifiable random number generation.
- Chainlink Automation: Automates raffle execution based on time triggers.
- React & Tailwind CSS: Frontend for user interaction (optional, as per previous response).
- ethers.js: JavaScript library for blockchain interaction.
Open-Source and Transparent
Decentralized Raffle is an open-source project, fully transparent on the Ethereum blockchain. All transactions, random number generation, and winner selections are verifiable on-chain, ensuring trust and fairness. The project is freely accessible for developers to fork, audit, or extend.
How it works
If youre interested in understanding the technical details, I suggest you read the codebase expecially the Raffle.sol as it is the main contract of the project.
Visit the GitHub repository to explore the codebase, report issues, or submit pull requests.
Stay Connected
Follow me for updates on this projecet and other smart contract applications: