Let’s look at some of the functionality available to you with HTS. You will see that the ease of use and flexibility this service provides make HTS tokens an excellent alternative to tokens with smart contracts on Ethereum. For those coming from Ethereum, HTS functionality can be mapped to multiple types of ERC token standards, including ERC20, ERC721, and ERC1155 – you can learn more about the mapping in this blog post. Starting in early 2022, you can use HTS with smart contracts for cases needing advanced logic and programmability for your tokens.
In this part of the series, you will learn how to:
- Create a custom fee schedule
- Configure a non-fungible token (NFT)
- Mint and burn NFTs
- Associate and Transfer NFTs
Prerequisites
We recommend you complete the following introduction to get a basic understanding of Hedera transactions. This example does not build upon the previous examples.- Get a Hedera testnet account.
- Set up your environment here.
Create New Hedera Accounts and Generate Keys for the NFT
Let’s create additional Hedera accounts to represent users for this scenario, such as the Treasury, Alice, and Bob. These accounts are created using your Testnet account credentials from the Hedera portal (see the resources for getting started). Account creation starts by generating a private key for the new account and then calling a reusable function (accountCreatorFcn) that uses the new key, an initial balance, and the Hedera client. You can easily reuse this function if you need to create more accounts in the future. Once accounts are created for Treasury, Alice, and Bob, new private keys are generated to manage specific token functionality. Always provide the corresponding public key when specifying the key value for specific functionality.nft-part1.js
nft-part1.js
Console output:
Create a Custom Fee Schedule
Let’s start by defining the custom fees for the NFT. Custom fees are distributed to the specified accounts each time the token is transferred. Depending on the token type (fungible or non-fungible), you can specify a custom fee to be fixed, fractional, or a royalty. An NFT can only have fixed or royalty fees, so in this example, we’ll go with a royalty fee. This enables collecting a fraction of the value exchanged for the NFT when ownership is transferred from one person to another.nft-part1.js
Create a Non-Fungible Token (NFT)
These are the images for our NFT collection.
nft-part1.js
nft-part1.js
Console output:

Mint and Burn NFTs
In the code above for the NFT creation, the decimals and initial supply must be set to zero. Once the token is created, you will have to mint each NFT using the token mint operation. Specifying a supply key during token creation is a requirement to be able to mint and burn tokens. In terms of use cases, you may want to mint new NFTs to add items to your NFT class, or you may need to burn NFTs to take a specific item out of circulation. Alternatively, if you’re working with a fungible token (like a stablecoin), you may want to mint new tokens every time there is a new deposit and burn tokens anytime that someone converts their tokens back into fiat. In this case we’re creating a batch of five NFTs for a collection of five images. We’ll use a “token minter” function and a for loop to speed up the batch NFT minting from our array of content identifiers (CID array):nft-part1.js
nft-part1.js
Console output:
nft-part1.js
Console output:
Auto-Associate and Transfer NFTs
Before an account that is not the treasury for a token can receive or send this specific token ID, it must become “associated” with the token. This helps reduce unwanted spam and other concerns from users who don’t want to be associated with any of the variety of tokens created on the Hedera network. This association between an account and a token ID can be done in two ways, manually or automatically. Note that automatic associations can be done for both existing and newly created accounts. For the purposes of our example, we’ll do both.- Alice’s account will be updated to associate with the token automatically
- Bob’s account will be manually associated with the token ID
nft-part1.js
Console output:
NFT Transfer from Treasury to Alice
Now, let’s do the first NFT transfer and check the account balances before and after the send.nft-part1.js
nft-part1.js
Console output:
NFT Transfer from Alice to Bob
nft-part1.js
Console output:
Conclusion
You just learned how to create an NFT on the Hedera network at the native layer without the need to code complex smart contracts! You can create, mint, burn, associate, and transfer NFTs with just a few lines of code in your favorite programming language. Continue to Part 2 to learn how to work with compliance features like Know your Customer (KYC), update tokens, and schedule transactions. Then in Part 3, you will see how to pause, freeze, wipe, and delete tokens.Code Check ✅
Code Check ✅
nft-pt1.js