HTS: Fungible Token
Hello World sequence: Create a new fungible token using Hedera Token Service (HTS).
What you will accomplish
Prerequisites
Before you begin, you should have completed the following Hello World sequence:
Get started: Set up project
To follow along, start with the main
branch, which is the default branch of the repo. This gives you the initial state from which you can follow along with the steps as described in the tutorial.
You should already have this from the "Create and Fund Account" sequence. If you have not completed this, you are strongly encouraged to do so.
Alternatively, you may wish to create a .env
file and populate it as required.
In the terminal, from the hello-future-world
directory, enter the subdirectory for this sequence.
Reuse the .env
file by copying the one that you have previously created into the directory for this sequence.
Next, install the dependencies using npm
.
Then open the script-hts-ft.js
file in a code editor, such as VS Code.
Write the script
An almost-complete script has already been prepared for you, and you will only need to make a few modifications (outlined below) for it to run successfully.
Step 1: Configure HTS token to be created
To create a new HTS token, we will use TokenCreateTransaction
. This transaction requires many properties to be set on it.
For fungible tokens (which are analogous to ERC20 tokens), set the token type to
TokenType.FungibleCommon
.Set the token name and token symbol based on your name (or nickname).
Set the decimal property to
2
.Set the initial supply to 1 million.
Step 2: Mirror Node API to query the specified token balance
Now, query the token balance of our account. Since the treasury account was configured as your own account, it will have the entire initial supply of the token.
You will want to use the Mirror Node API with the path /api/v1/accounts/{idOrAliasOrEvmAddress}/tokens
for this task.
Specify
accountId
within the URL pathSpecify
tokenId
as thetoken.id
query parameterSpecify
1
as thelimit
query parameter (you are only interested in one token)
Using string interpolation, construct accountBalanceFetchApiUrl
like so:
Run the script
In the terminal, run the script using the following command:
You should see output similar to the following:
Open tokenExplorerUrl
in your browser and check that:
The token should exist, and its "token ID" should match
tokenId
. (1)The "name" and "symbol" should be shown as the same values derived from your name (or nickname) that you chose earlier. (2)
The "treasury account" should match
accountId
. (3)Both the "total supply" and "initial supply" should be
10,000
. (4)
Note: "total supply" and "initial supply" are not displayed as 1,000,000
because of the two decimal places configured. Instead, these are displayed as 10,000.00
.
Complete
Congratulations, you have completed the Hedera Token Service Hello World sequence! 🎉🎉🎉
You have learned how to:
Next Steps
Now that you have completed this Hello World sequence, you have interacted with Hedera Token Service (HTS). There are other Hello World sequences for Hedera Smart Contract Service (HSCS), and Hedera File Service (HFS), which you may wish to check out next.
Cheat sheet
Last updated