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

[web3] Time: 2025-07-11 11:20:52 Source: AIHackNode Author: ai Click: 191 times
to add here so we're going to saywho is truth and perceptionactually deploying this by sayingfrom we're going to say it's from thedeployer we're going to pass anyarguments to the Constructor in thisargs piece here which we just added asingle ARG so these brackets we're goingto make it a list of arguments wherewe're going to put the price feedaddress in here which we'll show you howto do in a second put price feed addressand then we're also going to do somecustom logging here so that we don'thave to do all that console.log stuffthat we've been doing this whole time weneed we need to put something in here weneed to put an address in here and youcan use this backstar to put like acomment in between your codeewe can't just do const address equalsyou know the address and stick it inhere well I mean we could but we're notreally parameterizing now right we'rekind of back to just hardcoding it hereso what can we do instead well what wecan do is we can actually use the chainID to do something like if chain ID is Xuse address y or if chain ID is z useaddress a so we can do something thatlooks like this and to enable thisfunctionality we actually take a pageout of the a GitHub so a is anotherprotocol that's on multiple chains andhas to deploy their code to multiplechains and work with multiple differentaddresses so what they do is they use anumber of different useful tricks butone of the main ones is using thishelper hardhead config now they're usingtypescript we're using JavaScript butit's going to be the same thing withthis config they have differentvariables depending on what network thatthey're actually on and depending on thenetwork that they're on they usedifferent variables so they use thisnetwork config almost to do exactly whatwe're trying to do here so what we wantto do is we're going to create a newfile at the root directory so just clickdown here new file and we're going tocallit helper hard hat config.js and this iswhere we're going to Define that Networkconfig and this is where we're going tosay hey if you're on network a use thisaddress Network B use this use thisaddress Etc so so we're going to createan object called const Network configequals and we're going to add a bunch ofstuff in here so our main Network thatwe're working with right now is rink Brink be has a chain ID of four so we'llsay chain ID 4 is going to be named rinkB and theFUSD price feedaddress is going to be the price feedaddress of rink B of the FUSD price feedso we're going to copy it from thedocumentation or from the GitHubwhatever you want to do and paste it inhere now we have a simple methodology ofkeeping track of different price feedsof different contract addresses acrossdifferent chains let's say for examplewe wanted to deploy to polygon as wellwell first what are we going to needwell we're going to need the chain ID ofpolygon so a quick little Google searchbrings us to the polygon documentationand we can see the chain ID is 137 soI'll do 137 put's a little brackets herewe'll sayname polygon then we'll do a comma FUSDprice feed and then we'll add the pricefeed of FUSD on polygon so docs. chain.link polygon or mtic and then we'll lookupFUSD and boom we see it right here we'dgrab this address and we paste it inwhat about the hardhead Network we'llget to that in just a second don't youworry and then at the bottom we need toexport this network config so our otherscripts can actually work with it sowe'll do module. exports equals Networkconfig and we're going to actuallyexport a couple of things from this filewhich is why we're doing it like thisinstead of that default way that Ishowed you before so back in our scriptnow what can we do well first we want togo ahead and and import that Networkconfig so it we'll sayconst Networkconfig equals require and the we'llimport it we'll go down indirectory to helper hardhead config saveand I just want to mention this one moretime just so that it doesn't confuseanybody this syntax here con Networkconfig with the little curly bracetaround it is the same as if I wentconst helperconfig equals this thing which helperconfig is now kind of this whole fileand then const Network configequals helper config do Network configso again this syntax is just kind of aneasy way to extrapolate or pull out justthe network config from this file sothat's how that works and that's why weexport it at the bottom so that we cando this please use the GitHub repositoryto ask questions and discussionsespecially about some of this JavaScriptstuff all right great so now that wehave this network config in here we cannow do this part where we say if chainID is z use a if chain ID is X use ysince our helper config is nicely inthis kind of dictionary key value pairstyle what we can do is we can say constFUSD price feedaddress equals Networkconfig at the chain ID because if we'reon chain ID 4 it'll be this object ifwe're on chanity polygon it'll be thisobject at the F us D pricefeed we're going to save this to FUSDprice feed address and now no matterwhat chain we're on whenever we runhardhead deploy if I run yarn hardheaddeploy D- NetworkRinke this chain ID is going to be fourand so it's going to use this price feedaddress if I do das Das Network polygonand I remember to add both rink B andpolygon to my network flag here thechanity is going to be 137 and it'sgoing to use this price feed address sothis is awesome this is exactly what wewant but is it everything that we wantthose of you who have been questioningwhile I have been coding and talking youmight be thinking okay well you talkedabout this mocking thing you talkedabout Local Host and hardhead and how dowe test this locally like this is how wego to a test net and a

(Editor in charge: cs)

Related content
Wonderful recommendations
Popular Clicks
Friendly links