A fully automated, fair, and decentralized smart contract raffle system powered by Chainlink VRF v2.5 for provable randomness and Chainlink Automation for scheduling.
Players join by paying an entrance fee, and winners are selected at fixed intervals with auditable fairness. Includes complete deployment scripts, mock configurations for local testing, and VRF subscription management automation.
The Decentralized Raffle contract automates lottery rounds:
- Players pay an entrance fee in ETH to join.
- Every set interval, Chainlink Automation checks eligibility to pick a winner.
- Chainlink VRF ensures winner selection is truly random and verifiable.
- Funds are transferred automatically to the winner.
Seamlessly deployable to Sepolia or local development networks using Foundry scripts with configurable parameters.
graph TD
A[Players] -->|Enter with Fee| B[Raffle Smart Contract]
B -->|Automated Check| C[Chainlink Automation]
C -->|Trigger| D[Chainlink VRF v2.5]
D -->|Random Number| B
B -->|Winner Selection + Payout| A
- ⛓ Fully On-Chain Raffle Logic
- 🎲 Provable Randomness via Chainlink VRF v2.5
- ⏳ Automated Intervals using Chainlink Automation
- 🔧 Environment-Aware Deployment (Sepolia or Local Mock)
- 🧪 Local Testing with VRF Mocks & LINK Token Mocks
- 🛠 Helper Scripts for VRF Subscription Creation, Funding & Consumer Assignment
- 🎯 Gas-Efficient Custom Errors & Events
├── src/
│ └── Raffle.sol # Main raffle contract
├── script/
│ ├── HelperConfig.s.sol # Network configs and mocks
│ ├── DeployRaffle.s.sol # Main deployment script
│ └── interactions.s.sol # VRF Subscription interactions
├── test/ # Unit and integration tests
│ ├── unit/
│ └── integration/
├── lib/ # External dependencies (e.gChainlink, forge-std)
├── foundry.toml # Foundry project config
└── README.md
Located in src/
Purpose:
Manages player entries, automates winner selection at fixed intervals using Chainlink VRF randomness.
Key Functions:
enterRaffle()
— Player enters by paying ETH ≥ entrance fee.checkUpKeep()
— Checks if conditions are met for a draw.performUpKeep()
— Requests randomness via VRF.fulfillRandomWords()
— Selects winner & transfers prize.
Events:
raffleEntered(address player)
winnerPicked(address winner)
RequestedRaffleWinner(uint256 requestId)
- Defines NetworkConfig for Sepolia and local (Anvil) environments.
- On local chain:
- Deploys
VRFCoordinatorV2_5Mock
+LinkToken
mocks.
- Deploys
- Parameters include: entrance fee, interval, gas lane, callback gas limit, subscription ID, LINK token address, deployer account.
- Loads config from
HelperConfig
. - If no subscription exists:
- Runs CreateSubscription and FundSubscription scripts.
- Deploys
Raffle
contract with config values. - Adds it as a VRF consumer via AddConsumer script.
Includes:
- CreateSubscription — Creates VRF subscription.
- FundSubscription — Funds subscription (local mock or actual LINK).
- AddConsumer — Authorizes deployed contract to request VRF randomness.
Prerequisites:
- Foundry installed.
- Node.js (optional, if integrating frontend).
- RPC URLs for Sepolia (Alchemy/Infura/etc.).
- LINK tokens & VRF subscription for testnet.
- git clone this repo and you will be ready to work with it
- [To know more about the tools and the specific versions to work with please refer to the] (#Makefile)
This is a link to the deployed version of this contract in sepolia: (https://sepolia.etherscan.io/address/0x0e92EA6f1E8Af8dBF12C94e8AB1fB2c7a93b4A83#code)
Contract address : 0x0e92EA6f1E8Af8dBF12C94e8AB1fB2c7a93b4A83
[Sepolia Etherscan] : (https://sepolia.etherscan.io)