The following sample will show you how to create a NFT on Hedera Hashgraph. We will first generate a request for the end user. Once validated, you will get notified for the NFT's creation success.
In order to get the fees from our service, you need to proceed as below :
constxactFees=awaitclient.getXactFeesCreateNFT();
Step 3: Initializing Create NFT
When initializing a NFT's creation, a request will be sent to the end user
/* Update the fields with your informations */constname='NFT Test';constdescription='Description of my NFT';constcategory=CategoryNFT.ART;constcreator='Johny.B';constcid=''; /* cid linked to the NFT - IPFS storage */constsupply=1; /* Nb of NFT available */constfromAccountId=''; /* Account ID of the user */constcustomRoyaltyFee= { numerator:1, denominator:10, fallbackFee:100,/* in Hbar */};/* Optional*/awaitclient.createNFT({fromAccountId, name, description, category, creator, cid, supply, customRoyaltyFee});
Step 4: Listen for the NFT's creation
Finally get notified when your NFT has been successfully created !
/* Subscribe to new Create NFT Validation */client.createNFTValidation().subscribe(nft => {console.log('NFT Created', nft);});
Code Check ✅
Your index.js file should look like this:
const { Client,CategoryNFT } =require("@xact-wallet-sdk/client");require("dotenv").config();asyncfunctioncreateNFT() {//Grab your api key from your .env fileconstapiKey=process.env.API_KEY;// If we weren't able to grab it, we should throw a new errorif (apiKey ==null) {thrownewError("Environment variables API_KEY must be present"); }/* Create a new instance of Client */constclient=newClient({apiKey});/* Init the connexion */awaitclient.initConnexion();/* Update the fields with your informations */constname='NFT Test';constdescription='Description of my NFT';constcategory=CategoryNFT.ART;constcreator='Johny.B';constmedia=''; /* base64 format */constsupply=1; /* Nb of NFT available */constfromAccountId=''; /* Account ID of the user *//* Request for NFT's creation */awaitclient.createNFT({fromAccountId, name, description, category, creator, media, supply});/* Listen for Creation's success */client.createNFTValidation().subscribe(nft => {console.log('NFT Created', nft); });}createNFT();