A secure, transparent, and automated Raffle (Lottery) contract built on Solidity, leveraging Chainlink VRF for tamper-proof randomness and VRF V2+ Automation for seamless execution.
-
✅ Provable Randomness via Chainlink VRF v2+
-
🔄 Automated Execution using Chainlink Automation (Upkeep)
-
⚡ Gas-Efficient with event logging and state transitions
-
📊 Transparent Logs for all participants
- Users enter the raffle by sending a fixed ETH amount.
- When conditions are met (like time or entries), the raffle enters the CALCULATING state.
- Chainlink VRF V2+ is triggered via automation.
- A truly random winner is selected and rewarded with the total ETH balance.
- The raffle resets automatically for the next round.
- Solidity – Core contract logic
- Chainlink VRF v2+ – Verifiable randomness
- Chainlink Automation – No manual intervention
git clone https://github.com/yourusername/raffle-vrf
cd raffle-vrf
forge install # or yarn install / npm install if using Hardhat
Create a .env file and add the following:
PRIVATE_KEY=your_wallet_private_key
ETHERSCAN_API_KEY=your_etherscan_key
VRF_SUBSCRIPTION_ID=your_vrf_sub_id
VRF_COORDINATOR=vrf_contract_address
LINK_TOKEN=link_token_address
GAS_LANE=your_keyhash
CALLBACK_GAS_LIMIT=500000
ENTRANCE_FEE=10000000000000000 # 0.01 ETH
INTERVAL=300 # Interval in seconds (e.g. 5 minutes)Using Foundry
forge script script/DeployRaffle.s.sol --broadcast --rpc-url <network> --verifyUnit Testing with Foundry
forge test With a Forked Mainnet/Testnet
forge test --fork-url https://eth-mainnet.g.alchemy.com/v2/YOUR_KEYenterRaffle() – Enter the lottery by paying ETH
checkUpkeep() – Chainlink checks if it’s time to run
performUpkeep() – Requests randomness
fulfillRandomWords() – Chainlink responds with random number, winner is picked
Daksh Mane
Solidity Developer | Blockchain Enthusiast
📧 dakshspaceygeek@gmail.com
🔗