Developer Quick-Start: NFTs and Metadata
Headshot Waylon
Sep 02, 2021
by Waylon Jepsen
Developer Evangelist

The Hedera mainnet was upgraded to v0.17.4 on September 2nd, 2021. It included the new functionality of HIP-17: NFTs — the ability for anyone to issue a non-fungible token on Hedera.

The Hedera Token Service has adopted the most ubiquitous pattern for creating NFTs via HIP-17 as a “Whole Non-Fungible” token. In this pattern, a token class is defined and each instance (token) within that class shares certain properties but differs on others — these other properties could be, for example, the numbered edition of a series of cards or artwork. Each NFT is expected to not be equal in value between different instances. It’s encouraged that all developers creating NFTs on Hedera adopt this new standard.

HIP-17: NFTs was submitted by Daniel Ivanov, Blockchain Solutions Architect at LimeChain, and HIP-10: Token Metadata JSON Schema was submitted by Sam Wood, CTO & Co-Founder, Susan Chan, Project Manager, Stephanie Yi, Software Engineer, and Khoa Luong, Software Engineer, at LutherSystems.

Developers looking to utilize NFTs on Hedera can reference this developer quick-start tutorial to start building NFTs right into their application. We’ll dive into a few real-world use cases and learn how to mint an NFT for them using code examples.

You can also get started by visiting the Hedera Token Service documentation for creating NFTs.

What is an NFT and when should I be using one?

NFT stands for non-fungible token. The word fungible essentially means replaceable or interchangeable — NFT’s are not interchangeable, nor are they replaceable. An NFT has a unique cryptographic signature as proof of its authenticity. Additional information is retained in the NFT, like the account ID of its creator and metadata associated with it. This is so people can store all sorts of digital information in the metadata, and you would be able to verify that the account ID matched that of the creator of the work.

Non-fungible tokens create a monumental amount of utility in the worlds physical assets (real estate, art, wine, cars, etc.), digital assets (digital art, music, in-game items), and other financial instruments (bonds, debt, loans) . Artists have taken to this technology like a storm, leveraging it to produce irreplaceable unique digital artwork. Additionally, the digital aspect of the token’s metadata allows individuals to build a digital experience instead of a traditional static piece. Audio data with mp4 data will enable people to create multimedia artwork with a wide array of functionality.

How to create an NFT on Hedera

To create an NFT in JavaScript on hedera using the hedera token service, you would utilize the familiar TokenCreateTransaction() Object.

Code Snippet Background
const demoToken = await new TokenCreateTransaction()
	.setTokenName(“Cookie”)
	.setTokenSymbol(“CRUNCH”)
	.setDecimals(0)
	.setInitalSupply(0)
	.setSupplyKey(PrivateKey.fromString(myPrivateKey))
	.setMaxSupply(10)
	.setTrasuryAccountId(myAccountId)
	.execute(client);

To create an NFT, you need to set the decimals equal to zero and the initial supply to zero (We will mint them later on). You decide who will be able to mint the tokens with the setSupplyKey() parameter. In the past, we have passed in a string to the private key fields, but here we need to make sure that our key is a private key object. This is done with the PrivateKey module from the SDK. The two new parameters we will configure are the TokenType and the SupplyType made available through the SDK. The total amount of NFTs is configured with the MaxSupply; we have set it equal to 10.

Code Snippet Background
const tokenReceipt = await demoToken.getReceipt(client);
const tokenId = tokenReceipt.tokenId;
console.log(“The new token ID is: “ + tokenId);

Now we can get the token ID. Even though we haven’t minted any, we still have created the token type. We will use TokenId to mint tokens and create an NFT ID. Here is where we create token 1/10 of our limit run of NFTs.

Code Snippet Background
const token_1 = await new TokenMintTransaction()
	.setTokenId (tokenId)
	.setMetadata([[Buffer.from("Some Metadata")]]) // immutable, can hold a uri for storage
	.execute(client)

Metadata Options

When it comes to storing the metadata there are three options depending on the use case requirements. The primary things to consider when selecting how you want to store the metadata of your NFT is size and cost. Below these three options are ordered in abilities to handle different file sizes.

Schema

Additionally, to maintain interoperability with other networks it is highly recommended you store the metadata according to the schema outlined in Hip-10. An example of this is provided below. For more information on the type and description of each of these fields take a look at the corresponding hip.

Code Snippet Background
{
	“name”: “Chloe Artwork”,
	“description”: “Chloe Searching For Light Artwork Test Token”,
	“image”: “https://dev.luthersystemsapp.com/chloe_assets/SearchingForLightNo_81_20/image_part_005.jpg”,
	“localization”: {
		“uri”: “https://dev.luthersystemsapp.com/nft-test-{locale}.json,
		“default”: “en”,
		“locales”: [“en”, “es”, “fr”]
	}
}

Locally

If your metadata is less than 100 bytes you can actually store it directly in this field when minting the NFT. Keep in mind that this field is immutable, so once it is set, it can never be changed. Notice that you wont be able to store multimedia here and should store such assets on a distributed storage service like Filecoin or the Hedera File Service.

Hedera File Service

For files greater than 100 bytes and less than 30kb It is recommended to store the metadata on the Hedera File Service. Using the fee calculator for filecreate() this is estimated to be 36 cents per 90days. If metadata is stored on the Hedera File Service, the uri for the metadata should be provided in the setMetadata([“URI goes here”]) field. To calculate the cost based on the number of bytes, please visit the Hedera Fees Estimator: https://www.hedera.com/fees/

Filecoin

If you want to store high-resolution images appropriate for art and other rich multimedia, It is encouraged that File Coin is used. File coin supports distributed large file storage for fractions of a cent. Here is a link to the cost allocations for storing on Filecoin. And the documentation can be found here.

NFT Applications on Hedera

TOKO DLA Piper

TOKO is a digital asset creation engine created by the global law firm and governing council member DLA piper. The Hedera Token Service (HTS) enables TOKO to quickly issue non-fungible tokens representing various asset classes, such as real estate, fine art, intellectual property, ESG, debt restructuring, fund structuring, equity / digital IPO, and reinsurance. With the legal background from DLA Piper, TOKO can clarify and incorporate various legal implications of tokenized asset classes for their clients. HIP-17 allows TOKO to integrate greater programmable detail and granularity into their platforms regarding the tokenization of unique assets.

Calaxy: The Creators Galaxy

Calaxy enables creators to create single, non-fungible tokens and provide gas-less transactions to transfer them. Calaxy is making it free for creators on the platform to mint their own NFTs and ‘Calaxy Collectibles', while also enabling ‘NFT drops’ by creators, athletes, and artists. Collectables on Calaxy are minted as NFTs through the Hedera Token Service.