Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep144

[cpp] Time: 2025-07-11 11:56:07 Source: AIHackNode Author: c Click: 179 times
do log do ai tools for developersa little linelike this to let people know that thisdeploy script is done then we'll just doa module ual. exports. tags equals alland MOX so now that we have a vrfcoordinator V2 mock deployed we can comeback over to our raffle and make somecode around it similar to what we justdid with our deploy mocks we can say ifdevelopment chains doincludes network. name will do somestuff and we need to import developmentchains from our helper hardhead configand we need to import network fromhardhead my vs code automatically addedthem wow thanks vs code let's even justdo const args and make this variabledown here stick it in args our firstargument is going to need to be this vrfV2 coordinator so let's make a variablewe'll say let vrf coordinator V2address and if we're on a developmentchain we're going to grab that mockcontract so we'll say const brfcoordinator V2 mock equals await ethersdoget contract VFcoordcoordinator V2 Mock and then we can setVF coordinator V2 address equals VFcoordinator V2 mack.address cool we have the address hereelse if we're not on a local network thevrf V2 coordinator address is simplygoing to be derived from our Networkconfig so let's import the Networkconfig as well from our helper hardheadconfig and we'll say else vrfcoordinator V2 address equals Networkconfig of our chainID which which actually sorry we do needthe chain ID cons chain ID equalsnetwork. config dochain ID chain ID ofvrf coordinator V2 chainID vrf coordinator V2 all right perfectwe've got the setup to work with our vrfcoordinator V2 address what else do weneed from our raffle well we need anentrance fee we probably want to changethe entrance fee depending on what chainwe're on we're on a more expensive chainwe might want to make this higher thanothers so let's go ahead back to ourhelper hardhead config and make anentrancefee based off of the blockchain so forrink B maybe we want to make it 0.01 ethso we could say ethers do utils parseether of 0.01 and once again thank youcode for automatically dropping that infor me and we're also going to want anentrance fee for our hardap we couldalso set a default in here but let'sjust be a little bit more explicit sowe'll say31337 the name of this is hardap wedon't need to give it a vrf coordinatorV2 address because we're going to deploya mock but we do want an entrance feeand let's just give it the exact sameentrance fee here so we'll say ethers doutils parse ether 0.01 e all right greatso on our deploy here we can just sayconst and entrance feeequals Networkconfig chain ID of entrance fee let'sstart populating our args here so thefirst one is going to be2 coordinatoraddress next one is going to be ourentrance fee got it got it now we needour gas Lane on rink B and othernetworks there are different gas lanesthat we can choose from let's grab theonly gas lane from rinky the 30 Gay keyhLet's drop this of course into ourNetwork config as gas Lane pop it inhere for hard hat our mock actuallydoesn't care what gas Lane we're workingon because we're going to be mocking thegas Lane anyways so we can just say gasLane we can just go ahead and use thesame one or really anything here itdoesn't really matter now here we'll sayconst gas Lane equals Networkconfig chainID gas Lane we'll grab the gas Lanewe'll stick it into our argument arraywe've got this one we've got this onewe've got this one now it's time for thesubscription ID now if you haven't runthrough docs. chain. link for the chainlink vrf I highly recommend you do so sothat you can understand what thissubscription idea is we know that we canactually make a subscription ID usingthat front end using that website vf.chain. link which is great and all butwhat if we're on a local chain so we canget a subscription ID no problem in herebut uh it's a little bit harder on alocal network now I'm actually going toteach you how to create and fundsubscription ideas completely programprogrammatically so you don't even needto use the UI if you don't want tohowever for the purpose of this coursewe're still going to use the userinterface we're still going to use thatwebsite for us to get our ownsubscription IDs but you could 100%automate the process of creating asubscription ID and funding asubscription ID because when you createand fund subscription IDs you're justcalling create subscription and fundsubscription on that smart contract soon our development chain we have our vrfcoordinator V2 moach and what we'regoing to do and on our development chainwe're going to create that subscriptionso we're going to say contransaction response equals await vrfcoordinator V2 moach do createsubcription and then we'll run consttransaction receipt equals waittransactionresponse. weight wait one blockconfirmation and inside this transactionreceipt there's actually an event that'swith our subscription that we can getthis is another place where admittingevents is incredibly helpful so in factif we open back up that VF V2coordinator Mock and we look for createsubscription we see we emit subscriptioncreated with the subscription ID we canactually get this event emitted from ourtransaction receipt now to assign itlet's go ahead and create subscriptionID up here and then we'll saysubscription IDequals transaction risk reseat. events of z. ar. sub ID and againbe sure to watch that events video ifyou want to learn more about how to workwith events in hardap now that we have asubscription we need to fund thesubscription on a real Network you needthe link token to actually fund thesubscription the current iteration ofthe mock allows you to fund thesubscription without the link token sowhat we can do is we can just run awaitVF core donator mock VF cordinB2 mock fund subscription and we'll giveit the subscription ID and we'll need todo some fund amount for this we can justcreate some variable we'll say const VFsubscription fund amount equals ethersutils doparether of we'll say 30 VF subscriptionfund amount we'll just paste that downhere we could do this as well for realtest net or our live networks but

(Editor in charge: web3)

Related content
Wonderful recommendations
Popular Clicks
Friendly links