A decentralized, provably fair raffle system built on Ethereum using Chainlink VRF for secure randomness and Chainlink Automation for reliable execution.
- Truly random winner selection using Chainlink VRF
- Automated raffle execution with Chainlink Automation
- Configurable for multiple networks (Mainnet, Sepolia, Anvil)
- Comprehensive testing suite
- Easy deployment and interaction scripts
-
Clone the repository:
git clone https://github.com/zeroaddresss/provably-fair-raffle.git cd provably-fair-raffle
-
Install dependencies:
forge install yarn install
-
Set up environment variables:
cp .env.example .env
Edit
.env
and add yourPRIVATE_KEY
and other necessary variables.
-
To deploy on a local Anvil chain:
forge script script/DeployRaffle.s.sol --broadcast --rpc-url http://localhost:8545
-
To deploy on Sepolia testnet:
forge script script/DeployRaffle.s.sol --broadcast --rpc-url $SEPOLIA_RPC_URL
Raffle.sol
: Main raffle contractHelperConfig.s.sol
: Configuration helper for different networksInteractions.s.sol
: Scripts for VRF subscription management
enterRaffle()
: Allow users to enter the raffleperformUpkeep()
: Trigger the raffle drawing (Chainlink Automation)fulfillRandomWords()
: Callback for Chainlink VRF to provide randomness
The HelperConfig.s.sol
script provides configurations for:
- Mainnet Ethereum
- Sepolia Testnet
- Local Anvil chain
Adjust the parameters in this file to customize the raffle settings for each network.
Run the test suite:
forge test
For gas reports:
forge test --gas-report
-
Deploy the Raffle contract:
forge script script/DeployRaffle.s.sol --broadcast --rpc-url $YOUR_RPC_URL
-
Interact with the deployed contract:
cast send $RAFFLE_CONTRACT_ADDRESS "enterRaffle()" --value 0.1ether --rpc-url $YOUR_RPC_URL
- Chainlink VRF: For verifiable randomness
- Chainlink Automation: For automated raffle execution