Build your First NFT Dapp
With Shyft's API you can create applications to mint NFTs.
In this tutorial we will build a simple dapp that allows you to create an NFT on Solana blockchain, using Shyft APIs. At the end of this tutorial your newly minted NFT will be available in your own wallet.
Pre-requisites
To get started first thing first, let's install a browser extension of Phantom Wallet from below links:
Once installed, open Phantom in your browser, and follow the on-screen steps to create a new wallet. Refer to this guide, if you need help. Now, you have a public-private key pair that serves as an identity on blockchain.
Install nodeJs and npxx (node package executor)
Steps for mac:
Setup
Alright, now we are all set to create our first NFT minting dapp. We will use ReactJs to build a simple front end to allow you to interactively create a NFT. We will use VS Code to walk through the tutorial.
Authentication: Get your Shyft API key
x-api-key
is an authentication parameter, which gives you access to SHYFT APIs. You can get your own API Key from the SHYFT website. Just signup with your email id here and you can get it for free.
Setup react project
This creates the boilerplate code for your dapp, and file structure looks like below:
Let's dive into code
Let's create a new form for accepting all the details(parameters) we will require to create a new NFT. We have created a new component for the form, but you can also put this code directly under App.js
This is a simple form with takes in the following parameters:
Choose an image file that you want to mint as an NFT
Select the network (testnet, devnet, mainnet-beta)
Your phantom wallet's public key
NFT Name
NFT symbol
NFT description
External_Url, this can be link to any website that you want to put in. This will be visible in the phantom wallet account for navigation.
Number of editions of one particular NFT that can be minted. can be set to zero, if you want to create an one-of-a-kind NFT.
Royalty percentage of the NFT creator. Can be any value between 0 - 100.
Attributes associated to the NFT. It's a json array string, don't forget to Stringify as done in below code snippet.
Making the API call
Once we have the data, we are ready to make the API call. For this tutorial, we have used the axios
package to make the API call, but you can use any other methods including JavaScript's very own fetch.
axios
will allow your react application to make http request to Shyft's
server and create your NFT.
Now, let's create a function for making the API call using the data we have collected using the form we created in this tutorial.
The API Endpoint used:
We need to include the API key obtained from the SHYFT website in the header section of this API call. For details about this API and the parameters used, read the API Documentation here.
Link to complete App.js
file, after making the above changes: https://github.com/Shyft-to/example-projects/blob/main/example-projects-on-NFTs/my-first-nft-dapp-create-nft/src/create_nft.js.
Signing the Encoded Transaction
Now you are all set to mint your first NFT. Please note that this API does not require the private key, instead it uses the public key to sign the transaction required for the create operation.
Head over to the terminal and start the react app, by running:
npm run start
Your basic app will look like this:
All you have to do is enter the information in the fields and hit submit button.
As soon as you hit submit the request is sent to the Shyft server, and you have successfully created a new NFT transaction. Now, all you need to do is sign this transaction using your wallet and voila! Your newly created NFT will be added to your wallet. đ
Response :
Once we receive the encoded_transaction
in the response, the last and final step is to sign the transaction. We can sign encoded_transaction
in two ways, either using the wallet from the frontend, or by using the wallet's private key
from the backend.
You can read more about signing transactions on Solana here, or you can use our online dev tool for signing this encoded transaction available in the below link.
https://shyft-insider.vercel.app/
Once successfully signed, your NFT will be created and added to your wallet. đ
To check, if the NFT is created on the blockchain.
Go to https://explorer.solana.com/, select the network. (Devenet for this tutorial)
Paste the
mint
value (the on-chain address of your token) returned in the response in the search bar, you should get the details of the created NFT.Details of the transaction can be checked by pasting
txnId
from the response in the previous search bar on Solana explorer.
By now, NFT has already been received in your wallet!!
Go to Your Collectibles
tab of your phantom wallet, and you should see the newly created NFT.
Ending Notes
I hope you enjoyed this tutorial and are excited to dive deep into web3 awesomeness. Stay tuned for more such tutorials. If you want the complete code for this project with good looking UI, please checkout/fork and play with the code at this Repository.:
Feel free to check out our other tutorials on Reading all NFTs from a wallet and on Building NFT gated dApp as well.
Resources
Join our Discord
Thank you for your time. We hope you have a great time building dApps with SHYFT APIs. Happy hacking. đ
Last updated