LAB: Mint Your First NFT
Toggle full transcript
Hello and welcome back. In this lab, we're going to finally be able to mint our first
NFT on ImmutableX because we've laid the groundwork in the previous labs. The next step is actually quite simple. If you go to the Minting assets section of the Readme.md file,
then you'll see a description here of what needs to happen. Now, first and foremost, we need to go to our .env file.
And scroll down to the token ID section. This TOKEN_ID parameter will be used to determine which token
we mint. ImmutableX uses integer token IDs. Typically you would start with token one and then mint, token two, three, four, etc..
The key thing is that when you mint a token, you just need it to be unique. Otherwise the operation will fail. We've included a command that you can run to do the actual mint.
So in this case I'm going to mint token number one. And then the command is here. We basically do npm run mint.
Then we pass the dash dash, which tells NPM that we're about to pass some command line arguments to the underlying command. And then we pass a -w and have a wallet address.
The wallet address here will be the wallet that receives the minted NFT on ImmutableX.
Now to keep things simple, we can use the wallet address of the wallet that we've already created. So if we go to the top of our dot and they file, we can grab our owner
account address and put that in the clipboard and then we can run. npm run mint -- -w
and paste in our wallet address. We can see here that this is running the source onboarding slash five dash
mint script. And while we wait for that to execute, we can have a look at this script. The script is very similar to the other scripts that we've been looking at.
We retrieve our wallet from the command line -w argument, we grab our token ID from the environment which we added to our .env
file. We create our immutableX client. We create a payload that represents the token that we're trying to mint. This consists of the contract address, which is the address of the smart
contract that we deployed to the underlying Ethereum blockchain.
It includes the key of the wallet that we want to receive the NFT. And it contains the tokens or in this case token that we actually
want to mint, which consists of two arguments the id of the token and the blueprint.
The blueprint is data that gets provided at ImmutableX Minting time that is then passed through to Ethereum if you ever withdraw
the NFT. So it can then used by your smart contract to construct any token metadata on the Ethereum blockchain. The blueprint is also accessible via the IMX API.
Finally, we call the minter.mintV2() API call with our payload, which actually creates the NFT.
And we can see at the bottom here that we've output the result from that API call and it's given us the token ID, the contract address and the ImmutableX transaction ID as per the readme.md File.
Once you have minted your NFT, you can actually view it on the ImmutableX marketplace.
So we've got a URL template here that you can construct with your token ID. So in this case it was 1 and the contract
address that you've been using, which should also be in the output from the API. So if we copy this URL here and we
go to our web browser, then we should be able to visit that and see our NFT.
And you'll notice that the owner address here should equate to the owner address that you put in, which we can see here,
it does. And the name of the collection should match the name of the collection that we previously configured in our .env file,
which we can see it does. Now, something to keep in mind is that ImmutableX caches the metadata for the NFTs and it can take a while for
that case to update sometimes up to a couple of minutes. So in this case, we see that there's no image preview and the name and description
of this NFT are not present. However, if you wait until the metadata has been cached and
you refresh the page like you see here, then that metadata will update and look something like this. So there we go. An exciting milestone.
We've minted our first NFT on ImmutableX. Congratulations. In the next few chapters of this course, we're now going to expand on this knowledge and start exploring the other skills that you need
to be able to use this NFT minting capability for a real world scenario.