Current location: Current location: Home > go > Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep218 Text
Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep218
[go] Time: 2025-07-11 11:24:12 Source: AIHackNode Author: code Click: 147 times
to be future of ai 2025data applicationJson base 64 so we're going to do itlike this instead now the erc721 hassomething called a base URI that we'regoing to override and that we're goingto use so we're going to say functionunderscore base U this will be internalpure and we're going to override the onethat erc721 has and this is going toreturns a stringmemory and we're just going to returnthis bit right here and now we can usethis base U to append right we're goingto append this first part to our base 64encoded Json so in order to append themonce again we'll do ai. encodepacked and then we'll put this down hereand we'll say we're going to we're goingto concatenate base U to this massivething that we just created and then wesave and we Auto format so now this isobviously a bytes object and we want itto be a string so then all we got to dois type cast it as a string put anotherparthey down here and then we canactually just return this but basicallywhat we're doing is we're creatingadjacent string we encode it in bytesthat way we can encode it in base 64once we have it encoded in Bas 64 whichis going to look like this second stringit's going to look like here out we thenjust append this ini initial part butfor Json objects it's data applicationJson we we append that we do ABI doincode packed and then cast it to stringand then boom we now have a token URIthat'll look something like this andthen all we have to do is update ourimage URI with what we get from ourfunction up here and then we'll be goodto go so let's finish this out let's dothis so when our Constructor we passinga low SVG and a high SVG and what arethese low svgs and these high svgs wellwe're basically saying when the price ofthis asset is too low show a frown andwhen the price of the asset is high showa smiley face so we're going to give itthis frown SVG and this happy SVG asinput parameters low SVG and high SVG weprobably want to save those but we don'tnecessarily want to save them in liketheir SVG format so we just want tostore image U right we would just wantto store this string up here instead ofthe actual SVG so right in ourConstructor we can doicore low imageURI equals we have this SVG to image URIfunction where we can pass the lowSVG and then we can do the same thingfor the high image URI so now svgt imageURI is going to return something thatlooks like this and we're going to storejust this string this image URI on chainnow that we have the two of those we canuse that down below in our token Ufunction so when somebody calls token Uof token ID zero we're going to stickinto our Json either the low image U orthe high image URI and we're actuallygoing to base that off of the chain linkprice feed so how do we do that wellwe've already worked with chain linkprice feeds before so let's go ahead andadd it so we'll do yarn add- ddev atchain link SL contracts once that's doneat the top we can do import at chainlink SL contracts slsrc SLV 0.8 SLinterfaces SLaggregator V3 interface. Soul like soand then down here let's comment thisout for now we're going to want to calla price feed to figure out what theprice is and then show the high image orthe low image based off that so in orderto get a price feed in our Constructorlet's just add another price feedaddress price feed address and thenwe'll make another variable we'll doaggregator V3interface internal immutable iore pricefeed and we'll say in our Constructor Iprice feed equals aggregator B3interface at Price feed address and thenwhat we can do down here do a wholebunch of commas in here int 256 pricecomma comma comma equals I Price feed.latest round data and what we can do iswe can say if price is greater than orequal to some value then show one imageor ey otherwise show another one so wecan say string memory image U equalssore Loimage URI and then if the price ishigher than some value well great thenthe image URI we're going to use isgoing to be excuse me I is going toequal the high image U and then we haveimage URI down here so all we got to dois figure out the price so we can makeand in our mint we'll let the minorschoose the value that they want to useso we can say in 256 I value and we'llassign each nft their own high value sowe'll need to create like a littlemapping up top we'll say mapping you 256to un256 and let's just make this public forthe heck of it publicsore token IDto highvalue and we'll say that when they mintan nft we do s token ID to high valuebestore token counterwe set that equal to high value so whenthey mint they choose the high valuethat they want and then down here we'llsay if the price is greater than orequal to the high value of the token IDthen we'll use the high one otherwisewe'll just use the low one oops and thisneeds to be U 256 to int 256 excuse mesince we want to be able to compare thempretty equally and boom our contractlooks really good now the only thingwe'd want to add in here is probably anevent so we'd probably want to emit anevent anytime we mitted one of thesenfts so we might do event created nftwe'll say un 256indexed token ID comma int256 high value like so and then when wemint this nft we'll do AIT create an nftsore token counter comma I value andthen it's best practice to to have toupdate our token counter before weactually do the minting so we'll do thatas well okay there's a ton of code hereand like I said we definitely would nothave written all that code withouthaving compiled and written some testfirst but we decided we wanted
(Editor in charge: swift)
GenAI Essentials – Full Course for Beginners - Ep37Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep257
Related content
- Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep119
- Artificial Intelligence Full Course 2024 _ AI Tutorial For Beginners _ AI Full Course_ Intellipaat [DownSub.com](1).txt - Ep56
- Lul Tim on Killing King Von while Protecting Quando Rondo (Full Interview) - Ep13
- Artificial Intelligence Full Course 2024 _ AI Tutorial For Beginners _ AI Full Course_ Intellipaat - Ep39
- GenAI Essentials – Full Course for Beginners - Ep2
- Artificial Intelligence Full Course 2024 _ AI Tutorial For Beginners _ AI Full Course_ Intellipaat - Ep42
- Artificial Intelligence Full Course 2024 _ AI Tutorial For Beginners _ AI Full Course_ Intellipaat [DownSub.com](1).txt - Ep57
- ROSÉ_ The rosie Interview _ Apple Music - Ep8
- The Basics of Web3 - Ep5
- Chris Langan - The Interview THEY Didn't Want You To See - CTMU [Full Version; Timestamps] - Ep13
- Artificial Intelligence Full Course 2024 _ AI Tutorial For Beginners _ AI Full Course_ Intellipaat [DownSub.com](1).txt - Ep41
- Artificial Intelligence Full Course 2024 _ AI Tutorial For Beginners _ AI Full Course_ Intellipaat [DownSub.com](1).txt - Ep56
- Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep41
- How to use ChatGPT in 2025 _ ChatGPT Tutorial _ ChatGPT Full Course - Ep70
Wonderful recommendations
- Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep31
- [Hindi (auto-generated)] Machine Learning FULL Course with Practical (10 HOURS) _ Learn Free ML in 2025 _ Part-1 - Ep109
- Artificial Intelligence Full Course 2024 _ AI Tutorial For Beginners _ AI Full Course_ Intellipaat [DownSub.com](1).txt - Ep59
- [Hindi (auto-generated)] Machine Learning FULL Course with Practical (10 HOURS) _ Learn Free ML in 2025 _ Part-1 - Ep99
- GenAI Essentials – Full Course for Beginners - Ep74
- How to use ChatGPT in 2025 _ ChatGPT Tutorial _ ChatGPT Full Course - Ep64
Popular Clicks