Hedera
  • Welcome to Hedera — let’s build the future
  • Getting Started
    • Environment Setup
    • Web2 Developers
      • Transfer HBAR
      • Create a Token
      • Create a Topic
    • EVM Developers
      • Deploy a Contract
  • Tutorials
    • Smart Contracts
      • How to Mint & Burn an ERC-721 Token Using Hardhat and Ethers (Part 1)
      • How to Set Access Control, a Token URI, Pause, and Transfer an ERC-721 Token Using Hardhat (Part 2)
      • How to Verify a Smart Contract on HashScan
      • Deploy a Smart Contract Using Remix
      • Deploy a Smart Contract Using Hardhat and Hiero JSON-RPC Relay
      • Deploy Your First Smart Contract
      • Deploy a Contract Using the Hedera Token Service
      • Send and Receive HBAR Using Solidity Smart Contracts
      • Deploy By Leveraging Ethereum Developer Tools On Hedera
      • Deploy a Subgraph Using The Graph and Hedera JSON-RPC Relay
      • Deploy Smart Contracts on Hedera Using Truffle
      • The Power of Native Hedera Tokens as ERC-20 Tokens: A step-by-step guide
      • HTS x EVM - Part 1: How to Mint NFTs
      • HTS x EVM - Part 2: KYC & Update
      • HTS x EVM - Part 3: How to Pause, Freeze, Wipe, and Delete NFTs
      • Hedera Smart Contracts Workshop
        • Setup
        • Solidity
        • Hedera SDK JS
        • Hardhat and EthersJs
        • Outro
      • Foundry
        • How to Setup Foundry and Write a Basic Unit Test
        • How to Deploy and Verify a Hedera Smart Contract with Foundry
        • How to Test A Solidity Event
        • How to Fork Testnet on Latest Block
    • Consensus
      • Submit Your First Message
      • Submit Message to Private Topic
      • Query Messages with Mirror Node
    • Tokens
      • Create and Transfer Your First NFT
      • Create and Transfer Your First Fungible Token
      • Create and Transfer an NFT using a Solidity Contract
      • Structure Your Token Metadata Using JSON Schema V2
      • Hedera Token Service - Part 1: How to Mint NFTs
      • Hedera Token Service - Part 2: KYC, Update, and Scheduled Transactions
      • Hedera Token Service - Part 3: How to Pause, Freeze, Wipe, and Delete NFTs
      • Create Your First Frictionless Airdrop Campaign
    • Local Node
      • How to Run Hedera Local Node in a Cloud Development Environment (CDE)
        • Run a Local Node in Gitpod
        • Run a Local Node in Codespaces
      • How to Set Up a Hedera Local Node
      • Set Up a Hedera Local Node using the NPM CLI
    • More Tutorials
      • Create and Fund Your Hedera Testnet Account
      • How to Create a Personal Access Token (API Key) on the Hedera Portal
      • How to Auto-Create Hedera Accounts with HBAR and Token Transfers
      • How to Configure a Mirror Node and Query Data
      • How to Generate a Random Number on Hedera
      • Get Started with the Hedera Consensus Service Fabric Plugin
        • Virtual Environment Setup
      • Schedule Your First Transaction
      • How to Connect to Hedera Networks Over RPC
        • Configuring Hashio RPC endpoints
        • Configuring Hiero JSON-RPC Relay endpoints
        • Configuring Validation Cloud RPC endpoints
      • JavaScript Testing
      • Create a Hedera DApp Integrated with WalletConnect
      • How to Connect MetaMask to Hedera
    • Demo Applications
    • Starter Projects
    • Building on Hedera (course)
  • Networks
    • Mainnet
      • Mainnet Accounts
      • Mainnet Consensus Nodes
        • Node Requirements
          • FAQ
      • Fees
        • Transaction Records
    • Testnets
      • Testnet Accounts
      • Testnet Consensus Nodes
    • Localnet
      • Single Node Configuration
      • Multinode Configuration
    • Network Explorers and Tools
    • Release Notes
      • Consensus Node
      • Hedera Mirror Node
  • Core Concepts
    • Accounts
      • Account Creation
      • Auto Account Creation
      • Account Properties
    • Keys and Signatures
    • Schedule Transaction
    • Smart Contracts
      • Understanding Hedera's EVM Differences and Compatibility
        • For EVM Developers Migrating to Hedera
          • Accounts, Signature Verification & Keys (ECDSA vs. ED25519)
          • JSON-RPC Relay and EVM Tooling
          • Token Management with Hedera Token Service
          • Decimal Handling (8 vs. 18 Decimals)
          • Handling HBAR Transfers in Contracts
        • For Hedera-Native Developers Adding Smart Contract Functionality
          • Integrating ED25519 Accounts and Advanced Features Into Smart Contracts
          • JSON-RPC Relay and State Queries
          • Extending Token Management with Smart Contracts
      • Creating Smart Contracts
      • Compiling Smart Contracts
      • System Smart Contracts
        • Hedera Account Service
        • Hedera Schedule Service
      • Gas and Fees
      • JSON-RPC Relay
      • Deploying Smart Contracts
      • Smart Contract Addresses
      • Verifying Smart Contracts
      • Smart Contract Traceability
      • Tokens Managed by Smart Contracts
        • ERC-20 (Fungible Tokens)
        • ERC-721 (Non-Fungible Token)
        • ERC-3643 Real World Assets (RWA)
        • ERC-1363 (Payable Tokens)
        • Hedera Token Service System Contract
      • Wrapped HBAR (WHBAR)
      • Smart Contract Rent
      • Smart Contract Security
      • EVM Archive Node Queries
    • Tokens
      • Tokenization on Hedera
      • Hedera Token Service (HTS) Native Tokenization
        • Token Types and ID Formats
        • Token Properties
        • Token Creation
        • Custom Fee Schedule
        • Token Airdrops
      • ERC/EVM-Compatible Tokenization
      • Hybrid (HTS + EVM ) Tokenization
    • Staking
      • Staking Program
      • Stake HBAR
    • Hashgraph Consensus Algorithm
      • Gossip About Gossip
      • Virtual Voting
    • Transactions and Queries
      • Transaction Properties
    • State and History
    • Mirror Nodes
      • Hedera Mirror Node
      • One Click Mirror Node Deployment
      • Run Your Own Mirror Node
        • Run Your Own Mirror Node with Google Cloud Storage (GCS)
        • Run Your Mirror Node with Amazon Web Services S3 (AWS)
  • Open Source Solutions and Integrations
    • AI Tools for Developers
      • Hedera AI Agent Kit
      • ElizaOS Plugin for Hedera
      • Hedera Hivemind
      • Kapa AI
    • Asset Tokenization Studio (ATS)
      • Web User Interface (UI)
      • Frequently Asked Questions (FAQs)
    • HashioDAO
      • Governance Token DAO
      • NFT DAO
      • Multisig DAO
      • DAO Proposals
      • Local Environment Setup
    • Hedera CLI
    • Hedera Custodians Library
      • How to use it
    • Hedera Developer Playground
    • Hedera Wallet Snap By MetaMask
      • Hedera Wallet Snap Documentation
      • Tutorial: MetaMask Snaps – What Are They and How to Use Them
    • Interoperability and Bridging
      • LayerZero
    • NFT Studio
      • Airdrop List Verifier
      • Metadata Validator
      • NFT Rarity Inspector
      • NFT Token Holders List Builder
      • NFT Risk Calculator
      • Token Balance Snapshot
      • Hedera NFT SDK
    • Oracle Networks
      • Chainlink Oracles
      • Pyth Oracles
      • Supra Oracles
    • Stablecoin Studio
      • Core Concepts
      • Web UI Application
      • CLI Management
      • TypeScript SDK
    • Hedera Guardian
    • Hedera WalletConnect
  • SDKs & APIs
    • SDKs
      • Build Your Hedera Client
      • Set Up Your Local Network
      • Network Address Book
      • Keys
        • Generate a new key pair
        • Import an existing key
        • Create a key list
        • Create a threshold key
        • Generate a mnemonic phrase
        • Recover keys from a mnemonic phrase
      • HBAR
      • Specialized Types
      • Pseudorandom Number Generator
      • Transactions
        • Create a Batch Transaction
        • Transaction ID
        • Modify transaction fields
        • Create an unsigned transaction
        • Manually sign a transaction
        • Submit a transaction
        • Sign a multisignature transaction
        • Get a transaction receipt
        • Get a transaction record
      • Schedule Transaction
        • Schedule ID
        • Create a schedule transaction
        • Sign a scheduled transaction
        • Delete a schedule transaction
        • Get schedule info
        • Network Response Messages
      • Queries
      • General Network Response Messages
      • Accounts and HBAR
        • Create an account
        • Update an account
        • Transfer cryptocurrency
        • Approve an allowance
        • Delete an allowance
        • Delete an account
        • Get account balance
        • Get account info
        • Network Response Messages
      • Consensus Service
        • Create a topic
        • Update a topic
        • Submit a message
        • Delete a topic
        • Get topic messages
        • Get topic info
        • Network Response
      • Token Service
        • Token ID
        • NFT ID
        • Token types
        • Create a token
        • Custom token fees
        • Update a token
        • Update token custom fees
        • Update NFT metadata
        • Transfer tokens
        • Airdrop a token
        • Claim a token
        • Cancel a token
        • Reject a token
        • Delete a token
        • Mint a token
        • Burn a token
        • Freeze an account
        • Unfreeze an account
        • Enable KYC account flag
        • Disable KYC account flag
        • Associate tokens to an account
        • Dissociate tokens from an account
        • Pause a token
        • Unpause a token
        • Wipe a token
        • Atomic swaps
        • Get account token balance
        • Get token info
        • Get NFT info
        • Network Response Messages
      • File Service
        • Create a file
        • Append to a file
        • Update a file
        • Delete a file
        • Get file contents
        • Get file info
        • Network Response Messages
      • Smart Contract Service
        • Delegate Contract ID
        • Create a smart contract
        • Update a smart contract
        • Delete a smart contract
        • Call a smart contract function
        • Ethereum transaction
        • Get a smart contract function
        • Get smart contract bytecode
        • Get smart contract info
        • Hedera Service Solidity Libraries
        • Network Response Messages
      • Signature Provider
        • Provider
        • Signer
        • Wallet
        • Local Provider
    • Mirror Node REST API
      • Accounts
      • Balances
      • Blocks
      • Schedule Transactions
      • Smart Contracts
      • Tokens
      • Topics
      • Transactions
      • Network
    • Hedera Consensus Service gRPC API
    • Hedera APIs
      • Basic Types
        • AccountAmount
        • AccountID
        • ContractID
        • CryptoAllowance
        • CurrentAndNextFeeSchedule
        • FeeComponents
        • FeeData
        • FeeSchedule
        • FileID
        • Fraction
        • HederaFunctionality
        • Key
        • KeyList
        • NftAllowance
        • NftTransfer
        • NodeAddress
        • NodeAddressBook
        • RealmID
        • ScheduleID
        • SemanticVersion
        • ServicesConfigurationList
        • ServiceEndpoint
        • Setting
        • ShardID
        • Signature
        • SignatureList
        • SignatureMap
        • SignaturePair
        • SubType
        • TransferList
        • TransactionID
        • ThresholdKey
        • ThresholdSignature
        • TokenAllowance
        • TokenBalance
        • TokenBalances
        • TokenFreezeStatus
        • TokenPauseStatus
        • TokenID
        • TokenKycStatus
        • TokenRelationship
        • TokenTransferList
        • TokenType
        • TokenSupplyType
        • TopicID
        • TransactionFeeSchedule
      • Cryptocurrency Accounts
        • CryptoService
        • CryptApproveAllowance
        • CryptoDeleteAllowance
        • CryptoCreate
        • CryptoTransfer
        • CryptoUpdate
        • CryptoDelete
        • CryptoGetAccountBalance
        • CryptoGetAccountRecords
        • CryptoGetInfo
        • CryptoGetStakers
      • Consensus Service
        • Consensus Service
        • ConsensusCreateTopic
        • ConsensusUpdateTopic
        • ConsensusSubmitMessage
        • ConsensusDeleteTopic
        • ConsensusTopicInfo
        • ConsensusGetTopicInfo
      • Schedule Service
        • ScheduleService
        • SchedulableTransactionBody
        • ScheduleCreate
        • ScheduleDelete
        • ScheduleSign
        • ScheduleGetInfo
      • Token Service
        • TokenService
        • CustomFees
          • AssessedCustomFee
          • CustomFee
          • FractionalFee
          • FixedFee
          • RoyaltyFee
        • TokenCreate
        • TokenUpdate
        • TokenFeeScheduleUpdate
        • TokenDelete
        • TokenMint
        • TokenBurn
        • TokenFreezeAccount
        • TokenUnfreezeAccount
        • TokenGrantKyc
        • TokenRevokeKyc
        • TokenAssociate
        • TokenDissociate
        • TokenWipeAccount
        • TokenPause
        • TokenUnpause
        • TokenGetInfo
        • TokenGetNftInfo
        • TokenGetNftInfos
        • TokenGetAccountNftInfo
      • File Service
        • FileService
        • FileCreate
        • FileAppend
        • FileUpdate
        • FileDelete
        • FileGetContents
        • FileGetInfo
      • Smart Contracts
        • SmartContractService
        • ContractCall
        • ContractCallLocal
        • ContractCreate
        • ContractUpdate
        • ContractDelete
        • ContractGetByteCode
        • ContractGetInfo
        • ContractGetRecords
      • Miscellaneous
        • Duration
        • ExchangeRate
        • Freeze
        • FreezeType
        • GetByKey
        • GetBySolidityID
        • NetworkGetVersionInfo
        • NetworkService
        • Query
        • QueryHeader
        • Response
        • ResponseCode
        • ResponseHeader
        • SystemDelete
        • SystemUndelete
        • TimeStamp
        • Transaction
        • TransactionBody
        • TransactionContents
        • TransactionGetFastRecord
        • TransactionGetReceipt
        • TransactionGetRecord
        • TransactionReceipt
        • TransactionRecord
        • TransactionResponse
        • UncheckedSubmit
    • Hedera Status API
  • Support & Community
    • Glossary
    • Contributing to Hedera documentation
      • Contribution Guidelines
        • Creating Issues
        • Creating Pull Requests
        • Hedera Improvement Proposal (HIP)
        • Submit Demo Applications
      • Style Guide
        • Understanding different types of documentation
        • Use of HBAR and tinybars
        • Use of web2 and web3
        • Language and grammar
        • Formatting
        • Punctuation
        • GitBook Markdown Syntax
    • Discord
    • GitHub
    • Stack Overflow
    • Hedera Blog
    • Bug Bounty
    • Hedera Help
    • Documentation Survey
    • Meetups
    • Brand Guidelines
    • Status Page
Powered by GitBook
LogoLogo

INTRODUCTION

  • Fees
  • Core Concepts
  • Network Information

TOOLS

  • Bridge
  • Oracles
  • Explorers
  • Developer Portal & Faucet

RESOURCES

  • Status
  • Bug Bounty
  • Build on Hedera (course)
  • Documentation Survey
On this page
  • Introduction to Creating a Token
  • Prerequisites
  • Step 1: Navigate to the hts example in the project directory
  • Step 2: Guided Code Walkthrough
  • Create a Hedera Testnet Client
  • Create a Token Create Transaction
  • Sign and Submit the Token Create Transaction
  • Query the Account Token Balance Mirror Node API
  • Step 3: Run the Token Create Transaction Script
  • Code Check ✅
  • Complete
  • Next Steps

Was this helpful?

Edit on GitHub
  1. Getting Started
  2. Web2 Developers

Create a Token

PreviousTransfer HBARNextCreate a Topic

Last updated 1 month ago

Was this helpful?

Introduction to Creating a Token

This tutorial will walk you through a TokenCreateTransaction and create a fungible token. You will learn how to configure essential token properties, set up necessary keys and permissions, and submit your transaction to the Hedera network.

What you will accomplish

By the end of this tutorial, you will be able to:

  • Create a new fungible token using HTS.

  • Query the transaction via Mirror Node API.

  • View your transaction on a Mirror Node Explorer.


Prerequisites

Before you begin, you should have completed the following tutorials:


Step 1: Navigate to the hts example in the project directory

From the root directory of the hedera-future-world project CD (change directories) to the token create transaction example.

cd hts

If you completed a previous example in the series you can use to go back to the root directory and cd into this example.

cd ../hts

If you want to get back to the root directory, you can CD out from any directory with this command.

cd ../

Step 2: Guided Code Walkthrough

script-hts-ft.js
import {
    Client,
    PrivateKey,
    AccountId,
    TokenCreateTransaction,
    TokenType,
} from '@hashgraph/sdk';
import dotenv from 'dotenv';
import {
    createLogger,
} from '../util/util.js';

const logger = await createLogger({
    scriptId: 'htsFt',
    scriptCategory: 'task',
});
let client;

async function scriptHtsFungibleToken() {
    logger.logStart('Hello Future World - HTS Fungible Token - start');

    // Read in environment variables from `.env` file in parent directory
    dotenv.config({ path: '../.env' });
    logger.log('Read .env file');

    // Initialize the operator account
    const operatorIdStr = process.env.OPERATOR_ACCOUNT_ID;
    const operatorKeyStr = process.env.OPERATOR_ACCOUNT_PRIVATE_KEY;
    if (!operatorIdStr || !operatorKeyStr) {
        throw new Error('Must set OPERATOR_ACCOUNT_ID and OPERATOR_ACCOUNT_PRIVATE_KEY environment variables');
    }
    const operatorId = AccountId.fromString(operatorIdStr);
    const operatorKey = PrivateKey.fromStringECDSA(operatorKeyStr);
    client = Client.forTestnet().setOperator(operatorId, operatorKey);
    logger.log('Using account:', operatorIdStr);
}
ScriptHtsFt.java
package hts;

import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import com.hedera.hashgraph.sdk.*;

import io.github.cdimascio.dotenv.Dotenv;

public class ScriptHtsFt {
    public static void main(String[] args) throws Exception {
        System.out.println("🏁 Hello Future World - HTS Fungible Token - start");

	    // Load environment variables from .env file
        Dotenv dotenv = Dotenv.configure().directory("../").load();
        String operatorIdStr = dotenv.get("OPERATOR_ACCOUNT_ID");
        String operatorKeyStr = dotenv.get("OPERATOR_ACCOUNT_PRIVATE_KEY");
        if (operatorIdStr == null || operatorKeyStr == null) {
            throw new RuntimeException("Must set OPERATOR_ACCOUNT_ID, OPERATOR_ACCOUNT_PRIVATE_KEY");
        }
        if (operatorKeyStr.startsWith("0x")) {
            operatorKeyStr = operatorKeyStr.substring(2);
        }

	 // Initialize the operator account
        AccountId operatorId = AccountId.fromString(operatorIdStr);
        PrivateKey operatorKey = PrivateKey.fromStringECDSA(operatorKeyStr);
        System.out.println("Using account: " + operatorIdStr);]
}
script-hts-ft.go
package main

import (
	"encoding/json"
	"fmt"
	"log"
	"os"
	"strings"
	"time"

	"github.com/hashgraph/hedera-sdk-go/v2"
	"github.com/imroc/req/v3"
	"github.com/joho/godotenv"
)

type TokenMNAPIResponse struct {
	Name        string `json:"name"`
	TotalSupply string `json:"total_supply"`
}

func main() {
	fmt.Println("🏁 Hello Future World - HTS Fungible Token - start")

	// Load environment variables from .env file
	err := godotenv.Load("../.env")
	if err != nil {
		log.Fatal("Error loading .env file")
	}

	// Initialize the operator account
	operatorIdStr := os.Getenv("OPERATOR_ACCOUNT_ID")
	operatorKeyStr := os.Getenv("OPERATOR_ACCOUNT_PRIVATE_KEY")
	if operatorIdStr == "" || operatorKeyStr == "" {
		log.Fatal("Must set OPERATOR_ACCOUNT_ID, OPERATOR_ACCOUNT_PRIVATE_KEY")
	}

	operatorId, _ := hedera.AccountIDFromString(operatorIdStr)
	// Necessary because Go SDK v2.37.0 does not handle the `0x` prefix automatically
	// Ref: https://github.com/hashgraph/hedera-sdk-go/issues/1057
	operatorKeyStr = strings.TrimPrefix(operatorKeyStr, "0x")
	operatorKey, _ := hedera.PrivateKeyFromStringECDSA(operatorKeyStr)
	fmt.Printf("Using account: %s\n", operatorId)
	fmt.Printf("Using operatorKey: %s\n", operatorKeyStr)
}

Create a Hedera Testnet Client

To set up your Hedera Testnet client, create the client and configure the operator using your Testnet account ID and private key. The operator account covers transaction and query fees in HBAR, with all transactions requiring a signature from the operator's private key for authorization.

script-hts-ft.js
// The client operator ID and key is the account that will be automatically set to pay for the transaction fees for each transaction
client = Client.forTestnet().setOperator(operatorId, operatorKey);

//Set the default maximum transaction fee (in Hbar)
client.setDefaultMaxTransactionFee(new Hbar(100));

//Set the maximum payment for queries (in Hbar)
client.setDefaultMaxQueryPayment(new Hbar(50));
ScriptHtsFt.java
// The client operator ID and key is the account that will be automatically set to pay for the transaction fees for each transaction
Client client = Client.forTestnet().setOperator(operatorId, operatorKey);

//Set the default maximum transaction fee (in HBAR)
client.setDefaultMaxTransactionFee(new Hbar(100));
        
//Set the default maximum payment for queries (in HBAR)
client.setDefaultMaxQueryPayment(new Hbar(50));
// The client operator ID and key is the account that will be automatically set to pay for the transaction fees for each transaction
client := hedera.ClientForTestnet()
client.SetOperator(operatorId, operatorKey)

// Set the default maximum transaction fee (in HBAR)
client.SetDefaultMaxTransactionFee(hedera.HbarFrom(100, hedera.HbarUnits.Hbar))
	
// Set the default maximum payment for queries (in HBAR)
client.SetDefaultMaxQueryPayment(hedera.HbarFrom(50, hedera.HbarUnits.Hbar))

To avoid encountering the INSUFFICIENT_TX_FEE error while executing transactions, you can also specify the maximum transaction fee limit through the .setDefaultMaxTransactionFee() method and the maximum query payment through the .setDefaultMaxQueryPayment() method to control costs, ensuring your client operates within your desired financial limits on the Hedera Testnet.

🚨 How to resolve the INSUFFICIENT_TX_FEE error

To resolve this error, you must adjust the max transaction fee to a higher value suitable for your needs.

Here is a simple example addition to your code:

Copy

const maxTransactionFee = new Hbar(XX); // replace XX with desired fee in Hbar

In this example, you can set maxTransactionFee to any value greater than 5 HBAR (or 500,000,000 tinybars) to avoid the "INSUFFICIENT_TX_FEE" error for transactions greater than 5 HBAR. Please replace XX with the desired value.

To implement this new max transaction fee, you use the setDefaultMaxTransactionFee() method as shown below:

Copy

client.setDefaultMaxTransactionFee(maxTransactionFee);

Create a Token Create Transaction

Configure the token with the required properties:

  • Token Name: The name of the token.

  • Token Symbol: A publicly visible symbol for the token (e.g., hBARK).

  • Treasury Account ID: The account holding the initial token supply.

Other optional fields

Default values will apply if left unspecified:

  • No admin key makes the token immutable (unchangeable).

  • No supply key fixes the token's supply (no minting or burning).

  • No token type defaults to fungible.

Unlike NFTs, fungible tokens don’t require decimals or an initial supply of zero. For example, an initial supply of 10,000 units is represented as 1000000 in code to account for two decimals.

script-hts-ft.js
// Create the token create transaction
const tokenCreateTx = await new TokenCreateTransaction()
    //Set the transaction memo
    .setTransactionMemo(`Hello Future World token - ${logger.version}`)
    // HTS `TokenType.FungibleCommon` behaves similarly to ERC20
    .setTokenType(TokenType.FungibleCommon)
    // Configure token options: name, symbol, decimals, initial supply
    .setTokenName(`${yourName} coin`)
    //Set the token symbol
    .setTokenSymbol(logger.scriptId)
    //Set the token decimals to 2
    .setDecimals(2)
    //Set the initial supply of the token to 10,000
    .setInitialSupply(1000000)
    // Configure token access permissions: treasury account, admin, freezing
    .setTreasuryAccountId(operatorId)
    //Set the admin key of the the token to the operator account
    .setAdminKey(operatorKey) 
    //Set the freeze default value to false
    .setFreezeDefault(false)
    // Freeze the transaction to prepare for signing
    .freezeWith(client);
    
// Get the transaction ID of the transaction. 
// The SDK automatically generates and assigns a transaction ID when the transaction is created
const tokenCreateTxId = tokenCreateTx.transactionId;
logger.log('The token create transaction ID: ', tokenCreateTxId.toString());
ScriptHtsFt.java
// Create a HTS token create transaction
TokenCreateTransaction tokenCreateTx = new TokenCreateTransaction()
     //Set the transaction memo
     .setTransactionMemo("Hello Future World token - xyz")
     // HTS "TokenType.FungibleCommon" behaves similarly to ERC20
     .setTokenType(TokenType.FUNGIBLE_COMMON)
     // Configure token options: name, symbol, decimals, initial supply
     .setTokenName("htsFt coin")
     // Set the token symbol
     .setTokenSymbol("HTSFT")
     // Set the token decimals to 2
     .setDecimals(2)
     // Set the initial supply of the token to 1,000,000
     .setInitialSupply(1_000_000)
     // Configure token access permissions: treasury account, admin, freezing
     .setTreasuryAccountId(operatorId)
     // Set the freeze default value to false
     .setFreezeDefault(false)
     //Freeze the transaction and prepare for signing
     .freezeWith(client);

// Get the transaction ID of the transaction. The SDK automatically generates and assigns a transaction ID when the transaction is created
TransactionId tokenCreateTxId = tokenCreateTx.getTransactionId();
System.out.println("The token create transaction ID: " + tokenCreateTxId.toString());
// Create the token create transaction
tokenCreateTx, _ := hedera.NewTokenCreateTransaction().
     //Set the transaction memo
     SetTransactionMemo("Hello Future World token - xyz").
     // HTS `TokenType.FungibleCommon` behaves similarly to ERC20
     SetTokenType(hedera.TokenTypeFungibleCommon).
     // Configure token options: name, symbol, decimals, initial supply
     SetTokenName(`htsFt coin`).
     // Set the token symbol
     SetTokenSymbol("HTSFT").
     // Set the token decimals to 2
     SetDecimals(2).
     // Set the initial supply of the token to 1,000,000
     SetInitialSupply(1_000_000).
     // Configure token access permissions: treasury account, admin, freezing
     SetTreasuryAccountID(operatorId).
     // Set the freeze default value to false
     SetFreezeDefault(false).
     //Freeze the transaction and prepare for signing
     FreezeWith(client)

// Get the transaction ID of the transaction. The SDK automatically generates and assigns a transaction ID when the transaction is created
tokenCreateTxId := tokenCreateTx.GetTransactionID()
fmt.Printf("The token create transaction ID: %s\n", tokenCreateTxId.String())
Key terminology for HTS token create transaction
  • Token Name: This is the full name of the token. For example, "Singapore Dollar".

  • Token Symbol: This is the abbreviation of the token's name. For example, "SGD".

  • Decimals: This is the number of decimal places the currency uses. For example, 2 mimics "cents", where the smallest unit of the token is 0.01 (1/100) of a single token.

  • Initial Supply: This is the number of units of the token to "mint" when first creating the token. Note that this is specified in the smallest units, so 1_000_000 initial supply when decimals is 2, results in 10_000 full units of the token being minted. It might be easier to think about it as "one million cents equals ten thousand dollars".

  • Treasury Account ID: This is the account for which the initial supply of the token is credited. For example, using operatorId in this examplewould mean that your specified testnet account receives all the tokens when they are minted.

Sign and Submit the Token Create Transaction

The transaction must be signed using the operator's private key. This step ensures that the transaction is authenticated and authorized by the operator. Once signed, the transaction is submitted to the Hedera Testnet, where it will be processed and validated.

After submission, get the transaction receipt. The receipt contains important information about the transaction, such as its status and any resulting data. The receipt is used to confirm that the transaction was successfully processed and to get the new token ID. The token ID uniquely identifies the newly created token on the Hedera network and is required for any subsequent operations with the token.

script-hts-ft.js
// Sign the transaction with the operator's private key
const tokenCreateTxSigned = await tokenCreateTx.sign(operatorKey);

// Submit the signed transaction to the Hedera network
const tokenCreateTxSubmitted = await tokenCreateTxSigned.execute(client);

// Get the transaction receipt
const tokenCreateTxReceipt = await tokenCreateTxSubmitted.getReceipt(client);

// Get and log the newly created token ID to the console
const tokenId = tokenCreateTxReceipt.tokenId;
logger.log('tokenId:', tokenId.toString());
ScriptHtsFt.java
// Sign the transaction with the operator's private key
TokenCreateTransaction tokenCreateTxSigned = tokenCreateTx.sign(operatorKey);

// Submit the transaction to the Hedera network
TransactionResponse tokenCreateTxSubmitted = tokenCreateTxSigned.execute(client);

// Get the transaction receipt
TransactionReceipt tokenCreateTxReceipt = tokenCreateTxSubmitted.getReceipt(client);

// Get the token ID
TokenId tokenId = tokenCreateTxReceipt.tokenId;
System.out.println("Token ID: " + tokenId.toString());
script-hts-ft.go
// Sign the transaction with the operator's private key
tokenCreateTxSigned := tokenCreateTx.Sign(operatorKey)

// Submit the transaction to the Hedera network
tokenCreateTxSubmitted, _ := tokenCreateTxSigned.Execute(client)

// Get the transaction receipt
tokenCreateTxReceipt, _ := tokenCreateTxSubmitted.GetReceipt(client)

// Get the newly created token ID
tokenId := tokenCreateTxReceipt.TokenID
fmt.Printf("Token ID: %s\n", tokenId.String())

Query the Account Token Balance Mirror Node API

Mirror nodes store the history of transactions that took place on the network. To query the token balance of your account, use the Mirror Node API with the path /api/v1/tokens/{tokenId}. This API endpoint allows you to get the balance information about a specific token by replacing {tokenId} with your actual token ID. Since the treasury account was configured as your own account, it will hold the entire initial supply of the token.

  • Specify tokenId within the URL path

The constructed tokenVerifyMirrorNodeApiUrl string should look like this:

script-hts-ft.js
const tokenVerifyMirrorNodeApiUrl =
    `https://testnet.mirrornode.hedera.com/api/v1/tokens/${tokenId.toString()}`;
ScriptHtsFt.java
String tokenMirrorNodeApiUrl = 
    "https://testnet.mirrornode.hedera.com/api/v1/tokens/" + tokenId.toString();
script-hts-ft.go
tokenMirrorNodeApiUrl :=
    fmt.Sprintf(
    "https://testnet.mirrornode.hedera.com/api/v1/tokens/%s", tokenId.String())
Learn more about Mirror Node APIs

You can perform the same Mirror Node API query as tokenVerifyMirrorNodeApiUrl above. This is what the relevant part of the Swagger page would look like when doing so:


Step 3: Run the Token Create Transaction Script

In the terminal, cd into the ./hts directory and run the token create transaction script:

node script-hts-ft.js
gradle run
go mod tidy
go run script-hts-ft.go

Sample output:

🏁 Hello Future World - HTS Fungible Token - start  …
Read .env file
Using account: 0.0.1455

🟣 Creating new HTS token  …
↪️ file:///workspace/hello-future-world-x/hts/script-hts-ft...
The token create transaction ID:  0.0.46495@1722971043.397070956
tokenId: 0.0.5878530 

🟣 View the token on HashScan  …
↪️ file:///workspace/hello-future-world-x/hts/script-hts-ft...
Paste URL in browser:
 https://hashscan.io/testnet/token/0.0.46599 

🟣 Get token data from the Hedera Mirror Node  …
↪️ file:///workspace/hello-future-world-x/hts/script-hts-ft...
The token Hedera Mirror Node API URL:
 https://testnet.mirrornode.hedera.com/api/v1/tokens/0.0.46599
The name of this token: bguiz coin
The total supply of this token: 1000000 

🎉 Hello Future World - HTS Fungible Token - complete  …

Copy and paste the HashScan URL in your browser to view the token creation transaction details and verify 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 operatorId. (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.


Code Check ✅


Complete

Congratulations, you have completed the Create a Token tutorial in the Getting Started series for the Web2 Developers learning path! 🎉🎉🎉!

You have learned how to:


Next Steps

Continue building on Hedera with another tutorial in the series to explore more Consensus Node services.

You can follow along through the code walkthrough or skip ahead to execute the program .

Open the HTS token script (/hts/script-hts-ft...) in a code editor like , , or a instance. The imports at the top include modules for interacting with the Hedera network via the SDK. The @hashgraph/sdk enables account management and transactions like creating a token while the dotenv package loads environment variables from the .env file, such as the operator account ID, private key, and name variables.

To create a fungible token using the HTS, start by instantiating a TokenCreateTransaction. Set the token type to TokenType.FungibleCommon, which functions similarly to on Ethereum, meaning all token units are interchangeable.

: Fungible tokens, declared using TokenType.FungibleCommon, may be thought of as analogous to ERC20 tokens. Note that HTS also supports another token type, TokenType.NonFungibleUnique, which may be thought of as analogous to ERC721 tokens.

: This is the key that is authorized to administrate this token. For example, using operatorKey would mean that your testnet account key would authorize (required to sign related transactions) to perform actions such as minting additional supply.

You can explore the Mirror Node APIs interactively via its Swagger page: .

➡ You can learn more about the Mirror Nodes via its documentation: .

HTS transaction in Hashscan, with annotated items to check.

Have questions? Join the and post them in the channel or ask on .

VS Code
IntelliJ
Gitpod
ERC-20 tokens
Token Type
Admin Key
Hedera Testnet Mirror Node REST API
REST API
Java
JavaScript
Go
Hedera Discord
developer-general
Stack Overflow
here

Create a Topic

Transfer HBAR

Learn how to transfer HBAR, Hedera's native cryptocurrency, between accounts.

Create and Fund Your Hedera Testnet Account
Environment Setup

Learn how to create topics and publish messages using the (HCS).

LEARN MORE
LEARN MORE
Hedera Token Service (HTS)
Hedera Consensus Service