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

[solidity] Time: 2025-07-11 11:54:29 Source: AIHackNode Author: javascript Click: 186 times
automaticallyexecute picking a random winner we havea way for people to enter our raffle toenter this Lottery and women shaping space futurewe have abulletproof way to solve creating atruly Fair decentralized Lottery oh mygoodness let's do one more compile forgood measure HHcompile and these are just warnings sowe're good to go here our code iscompiling successfullylike I said normally this definitelyisn't going to be the way that you'regoing to write your smart contracts it'salmost impossible to write a full smartcontract without making any mistakes andwithout flipping back and forth betweenthe documentation I have already writtenthis contract many times myself and Istill made a whole bunch of mistakes soit is totally reasonable and totallyrational for anybody and everybody tomake mistakes going through this and touse resources and to write tests alongthe way now that we have our raffle dosocreated it's time to add everything elseso we're going to come over here'regoing to create a new folder and add ourdeploy folder per usual and we're goingto do exactly what we've already done acouple of times we're going to createsome scripts to deploy our rafflecontract now with our raffle contractthere's a couple of things in here thatwe want to make note of first thing isthat our Constructor right now isabsolutely massive there are a ton ofparameters in here that we need toaccount for let's take a look at ourConstructors and see if there's anycontracts that we're already interactingwith okay vrf coordinator V2 this is acontract address entrance fee no gasLane no subscription ID no call back gaslimit no and interval no so knowing thatthis is an address should be a tip thatah okay we're probably going to need todeploy some mocks for this since we'regoing to need to interact with a vrfcoordinator contract that's outside ofour project but let's go ahead and startworking on our raffle deployment scriptfirst and we know we're going to have todeploy some mocks so we'll just keepthat in mind so let's create a new file01deploy raffle JS and let's get starteddeploying our raffle contract now thisis going to look really similar to whatwe've done before and we're going to doit again here if you want to use yourprevious deploy scripts as a reference Iabsolutely recommend you do so but let'sget started with module that exportsequals an asyncfunction it's going to take get namedaccountsanddeployments as input parameters thenwe're going to do constdeploy log equalsdeployments then we're going to sayconst deployer equals await get namedaccounts let's go to our config andupdate module that exports to to havethis I'm just going to copy paste sothat deployer is going to be defaultedto account zero and player is going tobe defaulted to account one if you wantto go ahead and write this out feel freeto pause and write out your namedaccounts right now there's going to be alot of boilerplate in our hard hat.config.js so feel free to have theGitHub repo for this lesson up with youor your previous scripts that you'vealready written as a reference namedaccounts deployer and we're also goingto have a player named account so thatwe can separate different users ordifferent players who are interactingwith our contracts for now we're goingto grab our deployer and we're going toget started now similar to last time wewould just do const raffle equals awaitdeoyraffle comma and then add all of ourstuff in here right so this would befromdeployer args we're going to have a tonof args so we're going to come back tothis and then log is going to be trueand then we're going to have weightconfirmations there's a little bit moreboiler plate we need to work with herein our hardhead config we don't have anetwork here so let's add our Networkinformation so we can get those blockconfirmations we'll be specific in hereas well and we'll say default network isgoing to be hardap and then we'llsay networks and we'll add our Networkinformation definitely going to beworking withhardap which has a chain ID of31337 might as well put that in here aswell and block confirmations which isset to one we'll add this comma herewe're also going to be running somestaging tests on the rink be Network sowe'll add rink be in here with a chainID of fourblockconfirmations of six and we need to adda URL and then also some accounts forour URL we've done this 100 times we'lldo const rink rink B RPC URL equalsprocess. EMV dot rink VPC RL that'sprivate key blah blah blah we're goingto add all these same variables from ourlast projects so I'm going to ask you topause here and just copy paste all thoseVAR variables from our last project boomlike so since we're adding a rink PRPcrl private key coin market cap andether scan we're also going to want tomake sure new folder excuse me new fileAMV and we're going to drop all of ourinformation in here our ring prpc RLprivate key ether scan API key and thenour coin market cap API key as well nowthat we have our private key our rinkRPC RL down in url brpc url and foraccounts we're just going to add thatsingle private key so now for weightconfirmations is going to equalNetwork config doblockonformations or one we're going to have toimport network from hardhead which itlooks like my vs code automatically didfor me thanks vs code so this is howwe're going to deploy our raffleobviously we have a ton of argumentsthat we need to account for so let's getto it let's look at our raffleConstructor to see what we need to getokay well the first thing that we needto get vrf coordinator V2 we're going touse the same strategy we used in ourfundme project with using mock if we'reon a development chain and using theactual contract address if we're on atest net or a live Network so let's getto it so let's go ahead recreate thathelper Arad config.js and create thatconstNetworkconfig say it equals for hard hat we'regoing to use a mock so we don't need toput that in here for now but for rink Blet's go ahead put put a four in heresay the name is

(Editor in charge: rust)

Related content
Wonderful recommendations
Popular Clicks
Friendly links