Non-fungible Token
In this tutorial, we'll guide you through the process of working with Hedera Token Service (HTS) for non-fungible tokens (NFTs) using JavaScript scripts. These scripts cover essential operations such as creating an NFT, getting NFT information, minting and transferring NFTs, transferring and burning NFTs.
Prerequisites
Before you start, make sure you have the following:
Node.js installed on your machine.
A Hedera Hashgraph account for testing purposes.
Hedera JavaScript SDK installed in your project.
Step 1: Set Up Environment
Create a new directory for your project and navigate into it.
mkdir HederaNFTTutorial
cd HederaNFTTutorialInitialise your Node.js project and install the necessary dependencies.
npm init -y
npm install @hashgraph/sdk dotenvCreate a
.envfile to store your Hedera account details.
MY_ACCOUNT_ID=your_account_id
MY_PRIVATE_KEY=your_private_key
OTHER_ACCOUNT_ID=another_account_id
OTHER_PRIVATE_KEY=another_private_keyStep 2: Write NFT Creation Script
Create a file named createNFT.js and add the script for NFT creation.
Step 3: Write Get NFT Info Script
Create a file named getNFTInfo.js and add the script for getting NFT information.
Step 4: Write NFT Mint and Transfer Script
Create a file named mintTransferNFT.js and add the script for minting and transferring NFTs.
Step 5: Write NFT Transfer and Burn Script
Create a file named transferBurnNFT.js and add the script for transferring and burning NFTs.
Example Metadata
In your non-fungible token scripts, you can customize the token properties using metadata. An example metadata file, metadataExample.json, is provided below. This file contains sample metadata that you can use as a template or modify according to your specific requirements.
Feel free to explore and utilize the information in metadataExample.json to enhance the details associated with your non-fungible tokens during creation, minting, or other relevant operations. Remember to add the relevant code in required script for reading this metadata file.
Create a file named metadataExample.json and add the below script.
Step 6: Run the Scripts
Execute each script in the order of NFT creation, getting NFT info, minting and transferring, and transferring and burning. Ensure that you are following the proper sequence.
Conclusion
Congratulations! You have successfully executed scripts for various Hedera Token Service operations related to non-fungible tokens (NFTs). This tutorial covers fundamental steps, and you can further explore advanced features and integrations based on your specific use case.
Last updated