How to Mint an NFT with JavaScript
Tags: blockchain, javascript, distributedsystems
Published: 2021-09-15 14:01:55

This article will teach you how to create and mint NFTs and query their data using JavaScript on the hashgraph network. 

## What the heck is an NFT?

Before we get into it, let's go over what an NFT is. NFT stands for Non-Fungible Token. The word fungible means "able to be replaced" or "replace an identical item". In short, a Non-Fungible token is irreplaceable. For a digital asset to be irreplaceable, it needs to be unique. So the tokens we will be creating are unique and irreplaceable! Some use cases for these unique tokens ensure the authenticity of information. As of right now, the main usages of NFTs have been for digital art and collectibles but they can be used for so much more. For example, one could use NFTs to protect information like a deed to a house, certificates of authenticity, educational degrees, identity cards, or other crucial unique details.

## How do you make one?

For developers getting into web3 and blockchain technologies, it can be challenging to learn all the caveats of the new technologies such as learning a new programming language like Solidity. Minting an NFT on Hedera is simple and can be done with programming languages you are already familiar with like JavaScript. Making an NFT on the Hedera Network uses one of the network's core services, the Hedera Token Service(HTS). There are three officially supported SDKs for this service: Golang, Java, and JavaScript, as well as a variety of community-developed SDKs.

## Environment Set up

You are free to use any of your preferred environment tools. I recommend following this short (3min) [guide](https://www.youtube.com/watch?v=afQOcY9DfjY&t=49s) to set up with node.

## Code Check

After configuring your account Id, private keys, and the client. your code should look something like this

![Code Check](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbzh6s16wz0p22h1f96b.png)

## Creating the NFT

To create the NFT, you will need to import TokenCreateTransaction, PrivateKey, TokenType, and TokenSupplyType from the Hedera SDK, so include these in the require statement at the top of your file. Then you can use the TokenCreateTransaction passing in the appropriate configuration for your token. For reference, take a look at the example below.

![Token Create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nreckk7b3ejz7s7d1j95.png)

Here we create a token with a supply of 10. The initial collection must be zero so that you can set unique metadata for each NFT. It is also crucial that the decimals are zero so that your NFTs wont be fractional. The supply key is the key of the account permitted to mint the corresponding NFTs. We will go over minting in the next section.

## Minting

Minting an NFT is straightforward. We use the TokenMintTransaction from the Hedera SDK, so be sure to include it in your imports at the top of your file. The syntax is provided below.

![NFT Mint](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ittlws0pzjuuy54k6ki.png)

There are multiple options for metadata storage solutions. I wrote more in-depth about the possibilities and use cases [here](https://hedera.com/blog/developer-quick-start-nfts-and-metadata). However, it is very straightforward and typical for developers to use the [InterPlanetary File System](https://www.ipfs.io/) (IPFS). 

## Querying NFT Information

Now that your NFT has been minted, you might want to be able to access its metadata from the network. To do this, you can use the TokenNftInfoQuery, and NftId from the Hedera SDK.

![NFT Query](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lbk108l8jfnhdl28xslo.png)

This query returns the metadata of the minted NFT.  

If you liked this guide or have questions I will be going through some of these examples live on twitch so be sure to follow [HederaTV](https://www.twitch.tv/hederatv) on twitch.