- Loosely inspired by Patrick Collins' Solidity in Python tutorial, so may see some similar layouts
- I did all lessons prior to the Lottery one and then decided to figure out the Lottery on my own to help w/ the learning.
- Basic workflow to deploy the Lottery, buy tickets, end Lottery, and payout the winner
- deploy contract
startLottery(uint256 _ticketsTotal)
enterLottery(uint256 _numberTickets)
- Can use
entranceFeeWei(uint256 _numberTickets)
andticketsCanPurchase()
to help determine value to input for tickets and tickets you can purchase, respectively
- Can use
createNewSubscription()
-> need a subscription to request random # from chainlink VRF- see approximate min amount of LINK to fund subscription w/ in order to request a random # ->
linkForVrfRequest()
- fund subscription w/ LINK token using
topUpSubscription(uint256 amount)
- The contract must own the quantity of LINK you are "topping up"
- So will need to send some to the contract from a wallet first
- The contract must own the quantity of LINK you are "topping up"
- people enter lottery....... can start entering after step #3
calculateWinner()
-> this will initiate the following stepsrequestRandomWords()
which initiates the random # request- If the subscription hasn't been funded with enough LINK the random # will never be fulfilled
- I've needed to fund subscriptions with ~9 LINK, even though the request only takes ~.25 LINK
- Can check if request is pending
- using
prendingVrfRequest()
but if there are multiple consumers for the subscription, the request could be due to another contract - at https://vrf.chain.link/ and looking for your subscription ID
- using
- If the subscription hasn't been funded with enough LINK the random # will never be fulfilled
- set lottery state to
CALCULATING_WINNER
fullfillRandomWords()
which is returned automatically afterrequestRandomWords()
+ block_confirmations- close lottery, payout winner
- If no longer need the VRF subscription,
cancelSubscription()
- This sends all the VRF subscription's LINK back to the contract owner
- If the contract has any remaining LINK (i.e., you didn't
topUpSubscription()
with all the LINK you sent the Lottery contract),fullLinkWithdraw()
- This sends any remaining LINK the contract has back to the contract owner