Current location: Current location: Home > solidity > Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep166 Text
Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep166
[solidity] Time: 2025-07-11 11:36:56 Source: AIHackNode Author: go Click: 195 times
new file andI'll call it 02 or women and scienceeven like 9999 up date front.js and the reason I do 99 obviously isbecause we want this to be always thelast script in our deploy folder andthen we can just write a little scriptthat's connected we just write a littlescript that's connected to our front endhere so that whenever we deploycontracts no matter what chain we canupdate that constants folder on ourfront end so let's go ahead and createthat script right now we'll do module.exports equals asyncfunction and we'll add our stuff in herewe don't really need to deploy anycontracts cuz we're just updating thefront end so we can just leave theparameters of this one blank and theother thing I like to do becausesometimes I don't care about the frontend what I'll do is I'll only update thefront end if we've specified a EnVvariable so I'll create a EnV variablecalled update front end and then I'llset this to true and now in our scripthere we can say if process. EMV doupdate front end then we can just saylikeconsole.log updating front end and nowback in here right if I'm at if I'm inthe correct directory in here if we onhard hatdeploy you know I'll get this littleupdating front end and now we can updatefront end so let's do it so I'm actuallygoing to create one function calledupdate contractaddresses and this is going to be ourfunction that we're going to use toupdate contract addresses then I'm goingto make one called update ABI where wejust update the abis on the front end soso we're going to call this updatecontract addresses so I'm going tocreate a new function asyncfunction updatecontract addresses and first we're goingto get that raffle contract since we'regoing to need to get its address sowe're going to say con raffle equalsawait and we're going to do the samething we've been doing ethers dogetcontract raffle and then my vs code Autoimported it but doesn't con ethersequals require hardhead like so we haveraffle in here and we're going to wantto pass this raffle address to our frontend since this is going to be a variablethat we might use a lot of places wecould just add it like const front endlocation addresses file equals and we'regoing to give it the relative path towhere we are now which is going to beyou know if we CD down a directory tonext CH smart contract Lottery FCC and Ican even just copy this paste it in hereand then it's in the constants folderand it's going to becontract addresses. Json and let's getthe ABI file we'll say const frontendABI file it's going to equal and this isgoing to be nearly the same thing so wecan just copy paste that and then we'lldo slash ai. Json and now in our updatecontract addresses function we can sayconst currentaddresses equals and we can read againin our front end we can read from thisfile so I'll usually start it with justtwo brackets so that it's like Jsoncompatible in both of these files and soto read it we're going to say json.parsefs. readfile sync and we're going tohave to import going to say const FSequals require I know we've used FSextra in the past but this one we'rejust going to use FS which is going tobe our frontand addresses file we're going to readit in with UTF a encoding so now this isgoing to be our current addresses andwe're going to update the list ofcurrent addresses with some newaddresses because our contract addresseswe want this to be chain agnostic wewould do something like four you knowand then the addresses on rink B wecould do31337 and then the addresses on ourLocal Host right we we want to be ableto keep track of all the differentaddresses across all the differentchainsso back in our function here then we'llsay if ifnetwork. config dochain id. to stringin contract addresses Network config IDis in there then we're just going to goahead and add this new contract addressin there but before we add this newaddress in there let's just check tomake sure it's not already in there sowe're just going to say if contractaddresses of network. config chain id.TW string this is so long I don't wantto keep writing this I'm going to saycons chain ID equals Network configdochain id. to string and we're justgoing to use chainID if chain ID in contract address thenif if we don't already have do includesraffle doaddress we're going to go ahead andadd this new addressand then if the chain ID doesn't evenexist we're going to go ahead and docontract addresses currentaddresses equals or excuse me currentaddresses of chain IDequals and then we'll just create a newarray raffle that address we're sayingif the chain ID doesn't exist in currentaddresses we're just going to add thisnew array in there and then finally nowthat we've updated this object we'regoing to write it back to this filewe'll say fs. write file sync front andaddresses file and then we're going todo json. string IFI so we're going tostringify this Json object so we're justgoing to go ahead and write it back andthen at the bottom module. exports. tagsequals all and then front end all rightcool so we have a function to upgratethe contract addresses but we also needthe ABI so we're going to do date ABIand we're going to create anotherfunction async functionupdate ABI and in here we're going to dothe exact same thing con raffle equalsawait ethers do getContract raffle fx. write file syncfront and ABI oops just going to copypaste it front end ABI file and then topass just the ABI we can actually get itdirectly from this raffle object we canactually just do raffle dointerface. format ethers doils do formattypes. Json if you look in the ethersdocs ethers has this contract. interfacething which returns an interface whichis different from a solidity interfacebut it allows us basically just to getthe API with this on liner code so inour backend code here now if we run HHdeploy or HH node we shouldautomatically update our contractaddressesin our ai. Jon so let's
(Editor in charge: code)
Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep242Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep89
Related content
- Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep93
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep129
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep160
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep123
- Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep205
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep84
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep225
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep48
- Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep11
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep1
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep234
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep168
- Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep10
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep70
Wonderful recommendations
- GenAI Essentials – Full Course for Beginners - Ep102
- Harvard CS50’s Artificial Intelligence with Python – Full University Course - Ep104
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep67
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep102
- Web3 & Crypto Will Change The World As We Know It! Yat Siu - Ep1
- Generative AI Full Course – Gemini Pro, OpenAI, Llama, Langchain, Pinecone, Vector Databases & More - Ep253
Popular Clicks