text
stringlengths 61
434
|
---|
created NF T, will say you went to 56 indexed token ID comma int 256. I value like so. And then when we met this NFT, will do emit create n t, s underscore token counter, comma, I value. |
And then it's best practice to to have to update our token counter before we actually do the minting. So we'll do that as well. Okay, there's a ton of code here. And like I said, we definitely would not have written all that code without having compiled to run some tests first, but we decided we |
want to just write it all right off first. So and I did some misspellings. Let's just make sure everything compiles here. Awesome. Everything's compiled here. As you already know, a couple things that we're going to need to do to test this out. First thing we're gonna need to do is write our deploy function, we've got our basic NFT, we've got our random and f t, both of |
these hosted on IPFS. Now we're going to do a dynamic NFT that's hosted 100 percent on chain, and it changes based off the price of an asset. So let's do this. Oh, three, deploy dynamic, SVG |
nft.js. We are no, we're gonna need a little bit of boilerplate. So let's go to our basic NFT. And we'll just grab all this the first seven lines or so. And we'll just paste it in here. What do we need for our constructor? Well, we need a price feed address, a low SVG and a highest CG. Okay, so |
let's get all of those. So price feed address is something we've already done before. And we can add that into our helper Hardhead config. And we'll do one and a foreign local, we're going to use what we're going to use a mock. And if we're on Rinkeby, or an actual network, we're going to use an actual |
address. So let's go ahead to dark side chain that link will grab a price feed address, the M Aetherium. data feeds will go to rank B, rank B and let's just use eath USD copy that will make a new entry eath USD price feed like so. And for localhost, |
we're good. So since we know for localhost, we're going to need to do a mock. Let's see if we have a price feed mock. Okay, now we don't, we're gonna need a mock v3 aggregator dot soul. I just copied pasted mine. If you want, you can just go right to the to a repo here. Or you can copy from a previous section, |
just a reminder heart at f and f t FCC contracts asked moc v3 aggregator and this is using point 06 of solidity. So we're going to want to make sure that in our hard hat dot config, we have at least one 0.6 version, which we do so we're good there. |
That means in our deploy mocks, we're going to want to add So |
initial price will be 2000 decimals will be a team. So now we've waited to deploy mocks for that price feed. So we're gonna say const chain ID equals network dot config dot chain Id do if development chains dot includes network dot name, and |
the more we need to import development chains looks like where did say const eth USD akregator equals we'll get that price feed equals awaits ethers dot get contract Mark v3 Air |
gate tour, and then we'll up here we'll do let eath USD price feed address eath USD price feed address equals eath USD aggregate tore that address else will say the eath USD price feed |
address is going to be equal to what we find in the network config. Network config. Chain ID dot eth USD price. Okay, so we have the eth USD price feed rate. Now we need the lowest VG |
and the high SVG. So we're going to create a new folder in our images folder. So we go CD images, MK dir dynamic NF t. And now we'll have two folders in here dynamic which is empty and random, which has all the random stuff. If you want to use your |
own SVGs for this, you absolutely can. But if you want to just come to my images file and then save these images as so just come right click Save image as. Save them. and then drag and drop them into your images files here, you can absolutely do that. So now that we have those, we want to go ahead and read |
those into our script here. We'll say const, low SVG equals a weight. And we're going to use Fs again. So we're gonna do const Fs equals require Fs, or do await Fs dot read file sync, |
we're going to read in this file, which for me, it's at dot slash images slash dynamic NF T slash brown dot SVG. And we're using encoding of UTF eight. And then we'll say const. Hi, SVG |
equals await Fs dot read file sync. Copy this whole thing, because we're using the same stuff. This one's going to be happy about SVG. And that's it. So when price is good, we're gonna do happiness, SVG, when price is bad, we're gonna do |
frown at SVG. Now, let's go ahead and let's deploy this contract. So we'll say arguments or args equals, it's gonna be the price feed address, low SVG, and then high SVG. And we'll say const, dynamic S, G and F T equals await, deploy dynamic SVG |
and f t, comma little bracket here, from Deployer. args, args log true. And the weights confirmations, it's going to be network dot config, that block confirmations, or one |
will do some logging, I will do log to do that. But Larry, do some verification, I'm actually just going to copy paste that from our last script, because it's going to be exactly the same copy paste. But instead of random IPFS, it's going to be |
dynamic SVG and f t. The rest of this looks good. And that's just about it. So we'll do module, exports dot tags, equals and we'll do all dynamic. SVG. And we'll do main. Oh, okay. Let's |
try to see if our deploy script that we just created works. To do h h, or yarn hardhat deployed dash dash tags, die Namic SVG, that makes sense, because we didn't deploy the mocks. So we'll do tags, dynamic SVGs. And then also the mocks. Local |
network detected play marks, we deploy the marks, deploying dynamic SVG, awesome. You know what comes next? You Gosh, darn right, it's time for some tests. Now, once again, I'm going to |
encourage you to pause the video now and try to write your own test for this test for this section actually can be a little bit tricky. Since we are going to be manipulating the price of our mock aggregator, we are checking for these long strings, and such. So be sure to use the GitHub repository associated |
with this lesson, in case you get lost. Now, I want to show you what this looks like on a marketplace, like OpenCL. So we are going to deploy this to rink B. Now keep in mind test that can be slow. So you might want to be patient here. And you |
don't even have to do it if you don't want to. But it is kind of nice to see. Okay, that's what it really looks like. And you can go to the contract on chain once it's verified. And you can read the token URI and everything. And it's pretty fun. So let's just add one more bit to our deploy folder. Let's add |
a mint script that just emits an NF T for each one of these contracts. So we're going to create no for mint.js. And we're just going to have each one of these contracts mint NFT. Let's go ahead and do this. So in here, we'll do const ethers |
network equals require arhat. And then I'm going to do a little copy paste in. I'm just going to copy this part because I know I'm going to need that. We are going to need a deploy but we're not going to need to deploy. So I'll grab get named |
accounts, get named accounts, it's going to come right from there. So we have a Deployer. Our deployer is just gonna be used to mint them. First we'll mint the basic NF t. So we'll say const basic NF t equals wait ethers dot get contract, basic N |
ft, and we'll connect the deployer to it. And then we'll say const basic mint and if T or basic mint, TX equals await basic NF T dot mint NF t. And then we'll do a weight basic |
mint, TX dot weight one and then we'll do a little console dot log base Again, T index zero has token URI, we'll put in a little await basic NF T dot token URI of zero. That's it for the basic |
entity. Now we'll do our random IPFS and empty. So we'll say const, random IPFS NF t equals await ethers dot get contract, random IPFS and f t, connected to the Deployer. This one, we |
need a mint fee. So we'll say const, mint V equals await random IPFS NF T dot get mint fee. And then we'll do the mint. So we'll say const, random IPFS and ft mint, TX equals await, |
random IPFS and F T dot request and F team. And for this one, we need to pass a value, which is going to be the mint v.to string. Now for this one, just like what we saw in our tests, |
we're going to have to do this await new promise again, right, because we need to wait for it to return need to listen for those events, we probably should set up the listener first. So let's actually set up the listener first. So we're going to do await new promise, and we're gonna do async function. |
And we're going to do resolve reject. In here, we're gonna use that, that fun little arrow syntax in here. And now since we're in this function here, we actually set the timeout resolve like this, which means we have five minutes |
to time this out, you might want to bump this up even more five minutes might not be enough, this is gonna be 300 milliseconds here, we're gonna do that once again. So we'll say random IPFS and ft dot once. Once we get that NFT minted event, we're going to run an async function, we're just gonna |
do resolve. And inside here is where we can actually put, actually requesting the NFT. But below our listener, right, so in there, and then we can say if developments chains, that |
includes network dot name. So let's just make sure we import those development chains and network or affect them and chains that includes network dot name. So we're on a test net, this is where we go ahead and we pretend to be those mocks. So we'll say const Request ID equals random IPFS. Oh, |
actually, we're going to need to do const random IPFS and ft min TX receipt equals await on IPFS and empty minted TX dot weight one. So we're gonna need to get the receipt. And from the receipt, we can get the request ID. That events one dot args dot |
request id.to string. And then we can do const VRF. coordinator V to mock equals await ethers dot get contract, the RF coordinate for V to mock, connect this to the Deployer. |
And then we'll do a wait the RF corded and a Tor V to mock that fulfill random words with Request ID, random IPFS. And if T dot address, we can do console dot log random IPFS and have T |
index zero token URI to await random IP. That's NF T dot token URI of zero. Finally, we can do our dynamic SVG, NF t. So we can |
say const, high high value equals ethers.utils.do parse ether here. So we'll say 4000 $4,000 will be the high value. We'll say const. Dynamic SVG and f t equals await ethers |
dot get contract, dynamic. SVG and a T will connect it to the deployer say const by Namic, s, B, G, and f t mint, TX equals await dynamic SVG and F T dot mint and f t i value to string |
then we'll just do wait. This stat wait one. And finally console dot log dynamic. SVG NFT index zero token URI is going to |
be a weight dynamic. SVG and ft dot token URI of zero. Okay, I think that looks good. Let's try this on a local network. So we'll do yarn hard hat deploy. And we'll run all those scripts |
It looks like everything worked. So we have random, basic NFT index zero has a token year, I have this IPFS thing, random IPFS NFT. index zero has this thing. And then our SVG has this giant monstrosity, okay, perfect. And then we can even |
check, right, we can even grab this IPFS hash, we go to our IPFS node, or if you installed IPFS in your browser, or you're working with Brave, we can just pop it right into our browsers and see what it looks like. Right. And then if I zoom in, and adorable St. Bernard, with the image of the St. Bernard, |
looking like that, this one's also gonna be St. Bernard. And then of course, are SVG, which we can also copy, paste, and boom, that looks great. And then we can copy the image. And it's a frowny face or shad. But Awesome. Okay, so it's working locally for us. Now, let's go ahead and try to make this work |
on an actual test net. So hopefully, our helper hard hat config is set up correctly. And there's enough stuff in here where we need to make sure that we have a subscription ID, right, we're going to need to make sure we have a subscription ID. And we shouldn't call the mint function, right, because |
we're going to need to add our consumer to the VRF. Before we can actually meant so let me let's add some tags to our meant here. So we'll do module dot exports, dot tags equals, and we'll say all comma meant a while ago, I said okay, let's |
add a main tag. Now we're coming around to why we added this main tag here. So what we want to do is want to deploy all of these contracts. But before we finally meant for our IPFS one, we need to add that contract to our consumer, here's what we're |
gonna do, we're gonna run yarn, Hardhead, deploy dash dash network Rinkeby dash dash tags main. Now, this won't meant any of our NF T's, okay, won't mean to any of our NF T's, it'll just deploy those contracts might just sit around and wait a |
little bit for these to actually deploy. So this is a great time to go take a break, maybe go take a walk, get a sip of water, get a cup of coffee, whatever you want to do. Yeah, once everything is deployed, then we can go to V or F dot chain dot link, we're already connected here, we used our subscription. |
And then we would just add our IPFS consumer in here. And we'd be good to go. And All right, once everything goes through, and we have all three of our transactions on the blockchain, we can go ahead, we can grab our random IPFS NF T, we'll grab |
that address, we'll come back over to V or F dot chain dot link slash rink D, we'll go to our subscription ID, and we'll add a new consumer will add that contract address. So we'll go ahead and approve and Metamask. And once this goes through, we |
can finish running the mint part of our deploy folder. Once it's confirmed, we can close maybe we can do a little refresh, we should see our new address added as a subscription here. Now that we've added that we can mint one NF T from each one of these contracts are in hard hats, deploy dash dash tags meant dash |
dash network Rinkeby. And we'll have to wait a little bit for this too. Okay, now that we have them all minted, we should get a little output like this. Right? Basic NF t zero has token URI here. Basic random IPFS NF T has token your eye here. And then |
our SVG has this as a token year, right. So what can we do now? Well, let me go grab, I'll grab my wallet address and stick it into Rinkeby ether scan. And we can see we called mint request and mint again. And we created three contracts, right, |
we created our basic NFT, our random IPFS NFT and our dynamic SVG NFT. What we can do now is we can grab, we can copy the address of our contract. And we can go to test nets that open see that i Oh, |
and we can put that address in the bar here in the search bar here. Now this part is incredibly, incredibly variable. Okay, open C can be really slow. And it can take open see up to a couple of hours to register that a contract has been deployed to |
a test net. So if it doesn't show up right away, don't be discouraged. Don't let it drag you down. But if it does, you should be able to click on your collection and see the NFT is actually here. I'm going to grab our random IPFS NFT. Let's grab that contract address. I'm going to grab that test net site open |
c.io. Paste that address in there. And what do you know we do indeed see, random IPFS and f t, right and I've deployed a couple of them. So this one's v two, and we have our adorable Shiva in you right here. So this is what it looks like an open C |
now we can 100 percent verify that our code is good even if it doesn't show up on Open. See. If we go to the contract we go to read contract. And then we go to token URI punch and zero here. A query, grabbed this, stick it into our browsers, the JSON |
looks good. So let's grab the image URI. Paste that in. And if we can see this here, that means that our code is good. And you have successfully deployed a number of FFTs to the blockchain. We have learned a massive amount in this course, |
this is definitely one of the most jam packed one. And it's all about art. Right? Isn't that crazy? Let's do a quick refresher of this entire course here. So first off, we learned the basics of an NF T with our basic NF T dot Sol, we learn that these NF T's are based off of the ERC 721 standard. And |
that just means they have functions like name, token, Uri, etc. We learned that NF T's use this token URI to tell us what the token actually looks like a token, your eye will look something like this, it's going to be a name a description, it's |
going to have an image URL, which points to a different location for what the NFT actually looks like. It'll have stuff like attributes, it can have stuff like attributes, and a few other tags. This is known as the metadata of the NFT. And this tells us about the NFT. We can also have all that metadata |
on chain, of course, to customize it on chain, and make it look and grow and change and be interactive on chain, we learned more about IPFS, we actually wrote a script called upload to pinjarra.js, where we can actually programmatically upload images and files to another IPFS pinning service for |
us, we can of course, always use our own IPFS nodes if we want. Now this token URI can really be anything. And we hosted it on IPFS for our basic NFT and for our random NFT. But for our dynamic NFT, we actually hosted the token, you're right 100 percent On |
chain, so we didn't use IPFS. And we made this dynamic where the token URI actually changes based off of the price of a changeling price feed in our random IPFS NFT, we gave our NFT a chance we gave different rarities to the different dogs |
so that we could create programmatically rare NF TS where our pug is super rare. Our Shiva is sort of rare, and our St. Bernard is pretty common. So the fact that we got to ship it in you was awesome. We did some amazing deployments, we wrote some tests. Not only that, but we learned a lot about |
transactions, and how we can actually add whatever data we want to this data section. And a little bit more about what our transactions look like, and how we can actually use functions, selectors and function signatures to be able to call anything, right and we learn more about ABI dot encoding, and |
encoding packed and all this binary stuff if you want it to go deep into that. So this was an absolutely JAM PACKED session. And you should be incredibly proud of yourself, especially with your little puppy that you can see on open sea or you can see directly on ether scan, or you can just look at it and IPFS and be really proud of what you've done. But |
with that being said, huge congratulations on making this far. Definitely definitely definitely take a break here, and we'll see you in the next one. Okay, now we have less than fifth team, which is going to be |
our next JS NFT marketplace. And if you finish this lesson, you are a web three full stack monster, this is going to be our most complicated front end using the web three stack and using a lot of really advanced web three, and blockchain tools. So |
get really excited because we are going to learn a ton in this lesson. Now there are actually three different repos associated with this lesson. The first one is going to be our typical hard hat project. For the back end, after the hard hat project, we actually have two repos both are going to be our front end repos, |
and they're going to be slightly different. In this project, we're going to learn more about how events are so important and why events are so important, especially for off chain services. And so we're actually going to look at two different ways to work with them, one using the mirallas, or a centralized database, and then one using the graph. And the |
reason that I want to show both of these is that oftentimes, when people are looking to scale the projects, when people are looking to get things done really quickly, taking a more centralized approach can often be a little quicker, and you can sometimes add more functionality to your website. And there's still a lot of protocols that have decentralized backends. And |
centralized front ends. One such example, is open sea, open sea, for example, has the ability to actually like different and fts. Now, this isn't something that we would actually want to spend any gas on. But it is something that we're gonna have to store in some type of database somewhere, so that people have |
the ability to do that. So I want to show you this optional first way to build these front ends, since all of our logic is still going to be 100 percent. On chain, the front end matters a little bit less, because anybody can still interact with the contracts that we build on chain. Now in web three, we |
don't want to stay there. However, getting an MVP done getting a minimal viable project done is really, really important. So using a centralized server, like Morales, or centralized project can make us much quicker. In fact, we have been using centralized services, like alchemy, kind of throughout this whole project. But of course, I |
also want to show you the decentralized way to make your front end. So after we work with Morales, we're also going to show you how to use the graph then for to do all this event indexing. Now the graph is going to be the decentralized way we can make our front end and work with these events. And the graph also comes with its own graph repo. So we'll learn all about |
that once we get to the front end section. But let me show you what we're going to build because it is really cool. Now that we've learned a ton about how to make NF T's what they are, we're going to make our own NFT marketplace. And like I said, this is really going to be our deep dive into all these amazing front end tools. So here's what our front end is |
gonna look like. But what we can do is we can connect with our little connect button, we hit Metamask Metamask pops up, we'll go ahead and connect. And now that we're connected, we can see the different entities in here. And if we're on an address that's owned by us, it will say owned by you. And if we switch |
addresses, or UI will go ahead and update, connect there. And now we're owned by a different address. Now, if it's owned by us, we get this little hover that says Update listing. And right now it's worth 0.18. That's what it's listed for on our marketplace. If it's owned by us, and we click it, we can |
update it to a different price. Let's update it to 50 eath, or whatever your layer one currency is, we'll just say new listing price, we'll go ahead and confirm. And I'll say listing updated, please refresh, and what we can do them. And we'll mine some blocks on the back end, and boom, now we see that |
it's worth 50 here. Now if we switch to a different account, now we can see owned by blah, blah, blah, and the hovered now says by me, if his selected as a different user, I'm gonna get this transaction to actually buy it. Now go ahead and confirm |
that I'm gonna buy it, I get a little pop up. This is item bought successfully. Now if I do a little refresh, we'll now see that that NFT is gone from the marketplace, since we bought it right, it's no longer available to be sold. Now what we can do then is we can come over to sell NF Ts and at the bottom, we'll |
see a withdraw proceeds. So whenever somebody buys an NF T, the NFT marketplace actually keeps the proceeds that actually keeps the result of the sale. So if we switch back to our address that had the NF T listed, we can now see Withdraw 50 proceeds |
because we know that we have 50 eath, because we just bought that for 50. So if we hit withdraw, Metamask is gonna pop up, we can go ahead and confirm, wait a little bit as transaction populates, and boom once it goes through, we'll see now we have |
zero proceeds. Right, we withdrew everything from here. So what we can do now, is we can relist that NFT. So if we come back, let's go back to the one who just bought that NF t. If we know the address and the token ID of the NF t and we own it, we |
can go ahead and relist it, because we can place the address in here with the token ID Give us some sort of price, we'll submit, we'll approve giving the NFT marketplace access to our NFT to our little doggie. And then we'll go ahead and actually |
send the transaction to actually list the NFT on a marketplace that we get NFT listed successfully. After we remove some blocks in the back end, we can go back to the front end. And we now see, it's owned by us, instead of the original |
owner, right and set for 10 ether. And then we can of course, switch back to a different user, and we can have them actually buy. So this is going to be a NFT marketplace that's completely decentralized, we are going to learn a ton about front end a ton about indexing a ton about events, and |
why they are so powerful. And I'm really excited for you for this one. Because if you get through this one, you will have so many tools at your fingertips for working with the blockchain. Are you ready, let's jump in. Let's build the contracts first, |
and then we'll build the front end. Let's do this. Now this project is going to be based off the Arteon project, which is a completely open source decentralized smart contract NFT marketplace, I'll leave a link to it in the GitHub repo associated with this course, ours of course, is going to be a |