Get started with the Hedera Token Service - Part 2
Dec 07, 2020
by Cooper Kunz
Developer Evangelist

In part 2 of getting started with HTS we’re going to discuss some of the various administration functionalities. Similar to controlled mutability with Hedera’s supporting services, HTS leaves decisions about these API parameters to the developers and provides ultimate flexibility to however someone would like to create their tokens.

Minting and burning tokens

While creating and transferring tokens at incredibly low cost and high speeds is great for a majority of use cases, like micropayments, certain applications and protocols may need more robust features. With HTS, you can easily set up the creation (minting) and deletion (burning) of new tokens (assuming that the token was created with a “supply key”). For example, when issuing a stablecoin, you may want to mint new tokens every time there is a new deposit, and subsequently, burn tokens anytime that someone converts their tokens back into fiat.

Code Snippet Background

//Mint another 1,000 tokens and freeze the unsigned transaction for manual signing

const transaction = await new TokenMintTransaction()

.setTokenId(tokenId)

.setAmount(1000)

.freezeWith(client);


//Sign with the supply private key of the token

const signTx = await transaction.sign(supplyKey);


//Submit the transaction to a Hedera network

const txResponse = await signTx.execute(client);


//Request the receipt of the transaction

const receipt = await txResponse.getReceipt(client);

//Get the transaction consensus status

const transactionStatus = receipt.status;

console.log("The transaction consensus status " +transactionStatus.toString());

Code Snippet Background

//Burn 1,000 tokens and freeze the unsigned transaction for manual signing

const transaction = await new TokenBurnTransaction()

.setTokenId(tokenId)

.setAmount(1000)

.freezeWith(client);


//Sign with the supply private key of the token

const signTx = await transaction.sign(supplyKey);


//Submit the transaction to a Hedera network

const txResponse = await signTx.execute(client);


//Request the receipt of the transaction

const receipt = await txResponse.getReceipt(client);

//Get the transaction consensus status

const transactionStatus = receipt.status;

console.log("The transaction consensus status " +transactionStatus.toString());

Deleting tokens

Sometimes tokens can be used in seasonal games, or other contexts with a predefined lifespan. In these circumstances, it’s helpful to be able to delete the token from the network entirely, and therefore remove it from everyone’s accounts. Similar to other admin functionality and Hedera’s controlled mutability, if there are no administrative keys set during the token’s creation, deletion is not possible.

Code Snippet Background

//Create the transaction and freeze the unsigned transaction for manual signing

const transaction = await new TokenDeleteTransaction()

.setTokenId(tokenId)

.freezeWith(client);

//Sign with the admin private key of the token

const signTx = await transaction.sign(adminKey);

//Submit the transaction to a Hedera network

const txResponse = await signTx.execute(client);

//Request the receipt of the transaction

const receipt = await txResponse.getReceipt(client);

//Get the transaction consensus status

const transactionStatus = receipt.status;

console.log("The transaction consensus status " +transactionStatus.toString());

Updating tokens

If you create your tokens with an admin key, you’re also able to “update” that token, meaning change the metadata and characteristics of the token itself. For example, you can change the token name, symbol, or keys that are associated with its controlled mutability. You can create a token that initially has a 1 of 1 key for minting and burning, and over time, change this to a threshold or multisignature key. You can rotate the keys associated with compliance and administration, or even remove them entirely offering a more decentralized approach over time.

Code Snippet Background

//Create the transaction and freeze for manual signing

const transaction = await new TokenUpdateTransaction()

.setTokenId(tokenId)

.setTokenName("Your New Token Name")

.freezeWith(client);


//Sign the transaction with the admin key

const signTx = await transaction.sign(adminKey);


//Submit the signed transaction to a Hedera network

const txResponse = await signTx.execute(client);


//Request the receipt of the transaction

const receipt = await txResponse.getReceipt(client);


//Get the transaction consensus status

const transactionStatus = receipt.status.toString();

console.log("The transaction consensus status is " +transactionStatus);

These are just a few examples of when and why it’s helpful to have Hedera’s level of controlled mutability. Being able to mint, burn, delete, and update tokens when needed - in a transparent and cryptographically provable way - opens up entirely new opportunities in the tokenization industry. In Part 3 of this blog series we’ll look at different types of compliance functionality offered natively and out of the box, further opening the ease of integrations with HTS.