Create a Hedera Token Service (HTS) fungible token with metadata and upload related metadata files to IPFS using the Pinata SDK.
Metadata is commonly associated with non-fungible tokens (NFTs), where off-ledger storage of metadata such as artwork helps reduce on-ledger storage costs. However, metadata is also essential for fungible tokens (FTs), as it allows for storing additional information about a token beyond what is stored on the ledger.
Previously, there was a difference in how metadata was handled for NFTs and FTs on Hedera. While NFTs have a dedicated metadata field that points to a JSON metadata file, FTs originally lacked this feature and had to use the more generic memo field to store such pointers. However, this has since been resolved, and FTs now also have a optional metadata field, making the handling of metadata more consistent across token types.
It’s important to note that while both token types now support metadata, they adhere to different schemas. NFTs follow the HIP-412 schema, whereas FTs use the HIP-405 schema. This difference ensures that each token type has the appropriate metadata structure suited to its use case.
The JSON metadata for a fungible token includes the following information:
description
- human readable description of the token and corresponding projectsmallestUnitName
- the name of the smallest unit of the tokensmallestUnitSymbol
- the symbol of the smallest unit of the tokencreator
- the entity that created the tokencreatorDID
- the decentralized identifier of the creatoradmin
- if the token has an admin key, the entity that manages that keylightLogo
- a logo for the token designed for light backgrounds. svg is recommended.lightLogoType
- if the lightLogo is specified, its mime typedarkLogo
- a logo for the token designed for dark backgrounds. svg is recommended.darkLogoType
- if the darkLogo is specified, its mime typewebsite
address - the address at which additional information on the token or corresponding projectdiscussion
- the address at which the project’s community holds discussionwhitepaper
address - the address at which the project’s whitepaper can be foundproperties
- container for arbitrary token attributes not specifically listed above
See metadata-example.json
or metadata-schema.txt
.
See .env.example
.
Copy the .env.example
file to .env
, and fill in the required details, including your operator account credentials and Pinata JWT token. You will also need to fill in any necessary details for the metadata, if the upload script is not used.
See upload-metadata.js
This script uploads the token's metadata JSON to IPFS via the Pinata SDK. By uploading the token’s metadata to IPFS, we ensure that it is stored in a decentralized manner. The resulting IPFS hash (CID) is then used as part of the metadata in the token creation process. The resulting CID is saved to your .env file.
Run this command to upload metadata to IPFS:
node upload-metadata.js
See create-fungible-token-with-metadata.js
This script demonstrates how to create the fungible token while linking the metadata that was previously uploaded to IPFS. The metadata is attached to the token in the form of an IPFS URI, ensuring that token holders or users of the token can access the decentralized metadata.
Run this command to create the token with metadata:
node create-fungible-token-with-metadata.js
See update-fungible-token-metadata.js
This script demonstrates how to update the metadata fungible token on the Hedera Testnet using the Hedera SDK. It updates metadata reference stored on IPFS. The metadata contains a reference to an updated IPFS file containing additional metadata, such as the token creator, logo, whitepaper etc.
Run this command to update the token metadata:
node update-fungible-token-metadata.js
upload-metadata.js
:
- Uploading JSON metadata to IPFS...
Uploaded JSON successfully: bafkreigdmoccfta7fic3xt5imohlmra...
IPFS_CID updated in .env file.
create-fungible-toke-with-metadata.js
:
- Created new metadataKey: 302e020100300506032b65...
METADATA_KEY updated in .env file.
- Created token with ID: 0.0.4813...
TOKEN_ID updated in .env file.
update-fungible-toke-with-metadata.js
:
Token metadata before update: <Buffer 69 70 66 73 ... >
Status of token update transaction: SUCCESS
Token updated metadata: <Buffer 69 70 66 73 63 ...>
The TokenCreateTransaction
will throw a TypeError
when used with setMetadata
if an older version of the SDK is used.
- Discord: Unable to set the metadata when creating a new fungible token Question on Discord about metadata during the creation of a fungible token on Hedera.
- Fungible Token script adapted from original implementation in: Hedera Docs: Create and Transfer your first Fungible Token Official Hedera documentation providing a step-by-step guide to creating and transferring fungible tokens.
- Github repo: Hedera Example HTS NFT Original uploadJsonToIpfs.js script by Ed Marquez
- HIP-405
- HIP-412