A Raffle solidity smart contract connected to Chainlink VRF and Chainlink Automation and built on Foundry development framework.
This Raffle smart contract allows anyone to enter with an entrance fee of 0.01 eth, the participants address is then added to a list. This contract is automated with the help of 'Chainlink Automation', in our case chainlink automation monitors for a set time interval to execute a function which then requests 'Chainlink VRF' for a random number, this random number is then used to pick a winner from our participants list,the raffle is temporarily closed during winner selection process, the balance of the contract is then sent to the winning participant. After the balance is sent to the winner, all the previous participants data is erased and the raffle is open to take new participants
constructor(...)
- Initializes the raffle configuration and Chainlink VRF setup. Sets the entrance fee, raffle interval, VRF coordinator details, subscription ID, callback gas limit, initializes the timestamp, and opens the raffle.
enterRaffle()
- Allows a user to enter the raffle by paying the entrance fee. Reverts if insufficient ETH is sent or if the raffle is not open. On success, the sender is added to the players list and an event is emitted.
- Reverts : Raffle__SendMoreToEnterRaffle , Raffle__RaffleNotOpen
- Emits : RaffleEntered(address)
checkUpkeep(bytes)
- Called by Chainlink Automation to determine whether upkeep is needed. Returns true only if:
- The raffle is open
- The configured time interval has passed
- There is at least one player
- The contract has ETH balance
- This function does not modify state.
performUpkeep(bytes)
- Executed by Chainlink Automation when checkUpkeep returns true. Changes the raffle state to CALCULATING and requests a random number from Chainlink VRF.
- Reverts : Raffle__UpkeepNotNeeded
- Emits : RequestedRaffleWinner(uint256)
fulfillRandomWords(uint256, uint256[])
- Callback function executed by Chainlink VRF. Uses the received random number to select a winner, transfers the entire contract balance to the winner, resets the raffle state, clears player data, and restarts the raffle.
- Reverts : Raffle__TransferFailed
- Emits : WinnerPicked(address)
Interact with Raffle contract deployed on sepolia testnet -
https://sepolia.etherscan.io/address/0xa16346ab75516d757bd5219e62f044a66391ce3f#code