LAB: Mint An NFT With Metadata
Transcript
Toggle full transcript
Hello and welcome to the lab on how to mint an NFT in ImmutableX with metadata. Now, this lab assumes that you've done the
previous labs using the source card attached to this course. To get started. We simply need to go to the NFT metadata
section within the README.MD file, and there's a series of steps here that we can follow to mint an NFT that has metadata.
The first step is to set up an nft.storage API key. The reason we need to do this is we're going to be using IPFS or the InterPlanetary
File System to store the metadata and media for our NFTs. There's many services out there that can be used to interact
with IPFS. If you're storing metadata for NFTs, then NFT storage is probably one of the better options because it is free.
So, if you can click on the link to go to the nft.storage website.
Then the first step is to create an account. In my case, I'm going to log in using my GitHub.
Now, once we've logged in, we can go to the API keys section and create a new key.
We can give this key a name. So in this case, we're going to call it Makerversity. And create.
And we can see we've got the key here. Under actions, one of the options here is to copy that key, which then puts it in a clipboard.
The next step then, is to add that key to the .env file in the NFT_STORAGE_TOKEN value. So if we go to our .env file and we scroll down until the
metadata section, we can see we've got NFT_STORAGE_TOKEN, we can paste that token in, save the file and then we're ready to go.
The next step then is to upload the metadata. We've created a metadata folder within the source folder of the repository,
and this contains all of the data and images that we've provided as an example. Now, you're welcome to go in there and to change
these values. We've created five sample NFTs. So if I click on number one here, we can see that we've got an ImmutableX
metadata payload for this Ignis Emberstone NFT and we've got some traits here.
It's a fire mage with an attack of five, a defense of two and a magic of ten. And if we go to the other examples, you can see there's some other
ones that we've generated here. So you're welcome to change these. Or you can simply use them as they are. And similarly, under images, we've got one, two, three, four, five
.PNG. And you can see the images that we've generated here.
Again, you can change these images if you want or you can use them as they are. What we're going to do is we're going to upload this metadata to IPFS
using the token that we just set in our .env file. And to do that, we're going to run upload-metadata.
So if we pull open the terminal and we execute that command.
You see that it runs the src/metadata/one-upload-metadata.ts file. So if we open that file, then we can see what's happening
here. Essentially, we're pulling out our environment variable, the NFT storage token. We're creating a new NFT storage object
with that token. Well, looping through the five NFTs that we're going to mint and getting the PNG file
for each of the images in that image directory and adding them to an images array. And then we're going to upload those files.
The upload files function simply calls the stored directory method on the NFT.storage client.
Similarly, we run through each of the five NFTs. And we grabbed the JSON metadata within the data directory.
We changed the image URL to be the IPFS Gateway link from NFT storage to that image
using the content ID of the images that were uploaded to IPFS. And then we pushed that payload to this metadata array.
And then again we call our upload files method with that metadata array. And we can see here the output.
It uploaded. one, two, three, four, five .PNG. Two. This content ID within IPFS.
And then we uploaded our one, two, three, four, five metadata payload to this content ID within our IPFS.
So now that we've done that, the metadata is hosted and ready for us to use in minting our NFTs. The last step is to set the gateway URL of our metadata
in our .env file so that it can be used as part of minting our NFTs in ImmutableX.
And so for that we simply need to grab our gateway URL that is output here at the end. Get that into the clipboard and then in our .env
file we just need to find this CONTENT_METADATA_URI parameter, which is one of the previous parameters that we had set before. So we can change that now to be this new URL
that we have generated. So the next step then is to deploy a new contract and set up a new
collection for our metadata NFTs. Now, if you want, you could change the contract name and symbol.
So I'm going to call this My Metadata IMX Contract, and I'm going to call it MMIC for the contract symbol.
And we're going to run the previous command that we had gotten in our previous lab to deploy the contract.
So, this is going to take our contract metadata URL that we just updated in our .env file.
Feel free to pause the video at this point while you wait for
this operation to complete.
Okay, So now that this is being done, we can update the contract, address property within our .env file with the new contract address that we have here.
And similarly, if we want, we can change the collection metadata
to reflect the different collection that we're minting. So I'm going to call this Makerversity Lab Metadata NFTs in this case.
The next step then, is to create the collection in ImmutableX that corresponds to the contract that we just saved.
So make sure you've saved your .env file before executing this. And then we can run that one.
And then once we've done that, the next step is a new step that we haven't done previously. And this step allows us to add a metadata schema
to the collection that we just created. That tells it about the different traits that we have in our collection. Now, if we want to change this schema, we can edit it in the
metadata/4-add-metadata-schema.ts file, which is here. And this script basically sets up our
ImmutableX client connection and wallet for the private key of our collection owner.
And then takes a metadata schema payload. As you can see here, where we've got name, collectible, class, element, attack, defense and magic along with the
types of each of those and whether or not the collection can be filtered by them. And then calls the user.metadataSchemaToCollection
SDK call to register that metadata schema with the collection that we just created.
And so to execute that, we do this command here. npm run add-metadata-schema.
And we can say that we've got an OK from that API. So that metadata schema is now registered.
So now we can actually mint the NFT. First things first, we need to go back to our .env and make sure that the token ID
is set to one. Or if you want to run this multiple times, whichever token number that you want to mint; between one and five in this case was the ones that we've set up.
So we can execute our npm run mint command with our -- and our -w along with the wallet address that we want
to use. Which in this case I'm going to use our owner account address that we've previously registered in our
.env file. So this will now create token ID number one in the
collection that we just registered with ImmutableX and.
Voila, We've minted our NFT! We can click on the link to go to the marketplace to view that NFT.
Now it's worth pointing out that ImmutableX does sometimes take a little while to cache the metadata. So when you first view it, you're very likely to see something like this, which
looks very empty. This is particularly the case when using IPFS because IPFS gateways are often a little bit slow to respond
when they don't actively have the value cached. So, if we keep refreshing this every few seconds until
the metadata is there. Then. Here we go. You can see we've got our Ignis Emberstone name there.
We've got our image. And if we expand the properties here, we can see we've got our class, magic, attack, defense, element and collectible traits.
So there you have it. We've gone through, we've created a collection for our metadata driven NFTs.
We've uploaded both the media and the metadata to IPFS. We've created a collection with a metadata URL pointing to
the IPFS gateway of that metadata that we uploaded. And then we went through the same process that we have previously to mint an NFT
from that collection. And we've seen it here in the marketplace. Thanks so much for joining me for this lab.