A decentralized raffle smart contract using Chainlink VRF for provably fair random winner selection and Chainlink Automation for automated execution
Automated lottery system that-
- Accepts entries via entrance fee
- Automatically selects random winner using Chainlink VRF
- Distributes entire contract balance to winner
- Uses Chainlink Keepers to trigger winner selection at intervals
States: OPEN (accepting entries) → CALCULATING (selecting winner)
- Foundry
- For testnet/mainnet: Chainlink VRF subscription at vrf.chain.link, LINK tokens, and ETH
Main Functions:
enterRaffle()- Enter raffle (pay entrance fee)checkUpkeep()- Check if upkeep needed (Chainlink Keepers)performUpkeep()- Trigger VRF requestfulfillRandomWords()- VRF callback (selects winner)
Getters: getRaffleState(), getRecentWinner(), getNumberOfPlayers(), getEntranceFee(), etc.
Events: RaffleEnter, RequestedRaffleWinner, WinnerPicked
src/Raffle.sol # Main contract
script/DeployRaffle.s.sol # Deployment script
script/HelperConfig.s.sol # Network config
test/unit/RaffleTest.t.sol # Unit tests
test/integration/ # Integration tests
MIT
Ohburmaa