This is a decentralized Raffle (lottery) smart contract built on Solidity, leveraging Chainlink VRF v2.5 for randomness and Chainlink Automation for periodic execution.
Author: @0xVishh
Inspired by: Cyfrin's Foundry Course (Patrick Collins)
Purpose: Learning & Experimentation
- π Enter a raffle by sending ETH
- β± Automated upkeep using Chainlink Automation
- π² Random winner selection via Chainlink VRF v2.5
- π Uses
enumto manage state (OPEN,CALCULATING) - π§ͺ Fully tested with Foundry
enterRaffle()β Players enter the rafflecheckUpkeep()β Chainlink Automation determines if it's time to pick a winnerperformUpkeep()β Triggers Chainlink VRF requestfulfillRandomWords()β Chainlink VRF returns randomness to select winner
- Solidity: ^0.8.19
- Foundry: Forge, Anvil
- Chainlink:
- VRF v2.5 (randomness)
- Automation (timed execution)
- Test Framework: Forge standard tests (
.t.sol) - Scripting: Deploy, interaction, and helper config scripts
.
βββ contracts
β βββ Raffle.sol
βββ script
β βββ DeployRaffle.s.sol
β βββ interactions.s.sol
β βββ HelperConfig.s.sol
βββ test
β βββ RaffleTest.t.sol
βββ lib
β βββ (Chainlink libraries & foundry-devops)
βββ foundry.toml
- Configure your
.envwith your Chainlink subscription ID, VRF details, etc. - Deploy:
forge script script/DeployRaffle.s.sol --rpc-url <your_rpc_url> --private-key <your_key> --broadcastforge test- How Chainlink VRF v2.5 differs from older versions.
- Using Foundry for unit testing, mocking, and scripting.
- Automation-compatible contracts and the importance of
checkUpkeepvsperformUpkeep. - Managing state machines in smart contracts.
MIT β Free for learning and educational purposes.