This contract implements a sample raffle using Chainlink VRF Version 2. Participants can enter the raffle by paying an entrance fee, and a random winner is chosen periodically.
- Constructor
- External
- Public
- Internal
- Private
- View & Pure Functions
- Version: Solidity ^0.8.19
- License: MIT
The contract imports necessary interfaces and libraries from the Chainlink Brownie contracts.
The contract defines custom errors for various exceptional scenarios.
The contract interfaces with VRFCoordinatorV2Interface, VRFConsumerBaseV2, and AutomationCompatibleInterface.
The contract defines an enum RaffleState
to represent the state of the raffle.
- Chainlink VRF variables
- Lottery variables
RequestedRaffleWinner
: emitted when a random winner is requested.RaffleEnter
: emitted when a participant enters the raffle.WinnerPicked
: emitted when a winner is picked.
- Constructor: Initializes the contract with required parameters and sets initial state.
- enterRaffle: Allows participants to enter the raffle by paying the entrance fee.
- checkUpkeep: Checks if the upkeep of the raffle is needed.
- performUpkeep: Initiates Chainlink VRF call to get a random winner.
- fulfillRandomWords: Called by Chainlink VRF node to determine the winner and distribute the prize.
Provides public access to various state variables and contract parameters.