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

This blog post has been updated to include the latest capabilities of the Hedera Token Service.

See the updated version: Get started with the Hedera Token Service - Part 3: How to Pause, Freeze, Wipe, and Delete NFTs

In part 3 of getting started with HTS we’re going to discuss some of the various regulatory and application compliance 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.

KYC Key

If you want, you can also have more access controls around your tokens. To ensure that tokens only remain within parties that have been “authorized” to have them, e.g. known registered users, those who have passed identity verification, or otherwise, you can set what is called the “kyc” key for a particular token upon creation. These can be actual identity and compliance features, like AML requirements, or this can be used to reference any type of off-ledger authentication mechanism, like if a user has signed up for your application.

Enable KYC on a particular account

Code Snippet Background


//Enable KYC flag on account and freeze the transaction for manual signing

const transaction = await new TokenGrantKycTransaction()

.setAccountId(accountId)

.setTokenId(tokenId)

.freezeWith(client);


//Sign with the kyc private key of the token

const signTx = await transaction.sign(kycKey);


//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());

After the account’s KYC flag has been set to true, the administrator, identity provider, or compliance manager is able to revoke or disable the KYC flag. After their KYC has been disabled, this means that the account will no longer be able to receive or send tokens that require KYC.

Disable KYC on a particular account

Code Snippet Background

//Remove the KYC flag on account and freeze the transaction for signing

const transaction = await new TokenRevokeKycTransaction()

.setAccountId(accountId)

.setTokenId(tokenId)

.freezeWith(client);


//Sign with the kyc private key of the token

const signTx = await transaction.sign(kycKey);


//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());

Freezing accounts

Within enterprise and real world applications, there are circumstances and use cases that require accounts to be potentially frozen. This means that their account won’t be able to transact in a specific HTS token type, but would not affect their other interactions on the Hedera network, like transacting in HBAR. Just like the other controlled mutability on the network that is available with the rest of HTS’ admin and compliance functionality, if left undefined, there is no ability to freeze accounts.

Code Snippet Background

//Freeze an account from transferring a token

const transaction = await new TokenFreezeTransaction()

.setAccountId(accountId)

.setTokenId(tokenId)

.freezeWith(client);


//Sign with the freeze key of the token

const signTx = await transaction.sign(freezeKey);


//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

//Unfreeze an account

const transaction = await new TokenUnfreezeTransaction()

.setAccountId(accountId)

.setTokenId(tokenId)

.freezeWith(client);


//Sign with the freeze private key of the token

const signTx = await transaction.sign(freezeKey);


//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);


//Obtain the transaction consensus status

const transactionStatus = receipt8.status;

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

Wiping tokens


Similar to freezing accounts for a particular token, there are a number of circumstances in which tokens need to be removed from a particular account or accounts, for example, if a business needed to issue a refund or found fraudulent activity. If tokens are created with a wipe key, then compliance and administrators are able to “wipe” and remove tokens from a particular account balance. This would result in the tokens being effectively “burned” and the total supply of that token decreased by the account’s balance or the amount that was specified to wipe.

Code Snippet Background

//Wipe 100 tokens from an account and freeze the unsigned transaction for manual signing

const transaction = await new TokenWipeTransaction()

.setAccountId(accountId)

.setTokenId(tokenId)

.setAmount(100)

.freezeWith(client);


//Sign with the private key of the account that is being wiped, sign with the wipe private key of the token

const signTx = await (await transaction.sign(accountKey)).sign(wipeKey);


//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);


//Obtain the transaction consensus status

const transactionStatus = receipt.status;

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

With the Hedera Token Service, application developers at startups and enterprises can issue and configure tokens with ease. And with various types of regulatory compliance functionality — from account KYC to approve / deny lists, to freezing, and clawbacks — there are tons of out of the box options that expand on the current offerings available on alternative public distributed ledgers in the market today.

If you’ve started the process of building your application and are looking for technical help, transaction fee stipends, and marketing promotion, learn more and register for a grant. And if you’d like to join the technical discussion about HTS, join the #hedera-token-service channel in the official Hedera Discord.

We can’t wait to see what future you’ll build!