This project implements a provably random smart contract lottery using Solidity, Chainlink VRF v2.5, and Chainlink Automation. It is designed for educational and demonstration purposes.
- Users can enter the raffle by paying a ticket fee. All ticket fees are pooled as the prize for the winner.
- The lottery automatically draws a winner at regular intervals.
- Chainlink VRF is used to generate a provably random number for winner selection.
- Chainlink Automation triggers the lottery draw on schedule.
- Includes scripts for deploying, funding, and managing Chainlink VRF subscriptions.
- Comprehensive unit tests using Foundry.
- Foundry
- Node.js & npm (for Chainlink contracts and scripts)
- An Ethereum node or local Anvil instance
git clone <this-repo>
cd foundry-smart-contract-lottery-f23
forge installforge script script/DeployRaffle.s.sol --broadcast --rpc-url <YOUR_RPC_URL>forge script script/Interactions.s.sol:CreateSubscription --broadcast --rpc-url <YOUR_RPC_URL>
forge script script/Interactions.s.sol:FundSubscription --broadcast --rpc-url <YOUR_RPC_URL>
forge script script/Interactions.s.sol:AddConsumer --broadcast --rpc-url <YOUR_RPC_URL>forge testsrc/- Main contract codetest/- Unit testsscript/- Deployment and interaction scriptslib/- External dependencies
Edit script/HelperConfig.s.sol to set network-specific parameters such as VRF coordinator, subscription ID, and LINK token address.
MIT