facebook

A Comprehensive Guide to Fungible Token Development on Hedera

Calender

22nd November 2023

Clock

6 min read

Author
Yogesh Sahu

Senior Associate Consultant L1 - Development

This article explores a step-by-step guide on fungible token development on the Hedera Hashgraph network using JavaScript and the Hedera Hashgraph SDK. 

 

Hedera Hashgraph

 

Hedera Hashgraph is a distributed ledger technology and blockchain alternative that employs a unique consensus algorithm called Hashgraph. Designed for efficiency, security, and scalability, Hedera offers fast and fair transactions and utilizes a decentralized governance model. Its native cryptocurrency, HBAR, facilitates network operations and incentivizes users. Hedera's consensus mechanism achieves consensus asynchronously and avoids the energy-intensive proof-of-work approach. 

 

With features like smart contracts and file storage, Hedera aims to provide a robust platform for decentralized applications while prioritizing stability and sustainability in the evolving landscape of blockchain technology.

 

Check It Out | Hedera Hashgraph | Moving Beyond Blockchain

 

Prerequisites

 

Before diving into the code, ensure you have the following:

 

Hedera Testnet Account:

 

  • Set up a testnet account on Hedera Hashgraph to obtain your operator's private key and account ID.
  • Create a .env file to store your operator's private key (OPERATOR_PVKEY) and account ID (OPERATOR_ID).

 

npm i dotenv @hashgraph/sdk
const {
  ContractCreateFlow,
  AccountId,
  Client,
  PrivateKey,
  AccountBalanceQuery,
  // ... other imports ...
} = require("@hashgraph/sdk");
require("dotenv").config();

const operatorKey = PrivateKey.fromString(process.env.OPERATOR_PVKEY);
const operatorId = AccountId.fromString(process.env.OPERATOR_ID);
const client = Client.forTestnet().setOperator(operatorId, operatorKey);

async function main() {
  // ... code for client initialization ...

  let tokenCreateTx = await new TokenCreateTransaction()
    .setTokenName("HTSB")
    .setTokenSymbol("HTSB")
    .setTokenType(TokenType.FungibleCommon)
    .setDecimals(3)
    .setInitialSupply(100000000000000)
    .setTreasuryAccountId(operatorId)
    .freezeWith(client)
    .sign(operatorKey);

  let tokenCreateSubmit = await tokenCreateTx.execute(client);
  let tokenCreateRx = await tokenCreateSubmit.getReceipt(client);
  let tokenId = tokenCreateRx.tokenId;
  console.log(` - Created fungible token with ID: ${tokenId}`);
}

 

  • Creates a fungible token using the TokenCreateTransaction class.
  • Configures various parameters for the token, including name, symbol, type, decimals, initial supply, and treasury account.
  • Signs and executes the transaction on the Hedera network.
  • Retrieves the transaction receipt to obtain the generated token ID.

 

Conclusion

 

Creating fungible tokens on Hedera Hashgraph is a straightforward process, thanks to the Hedera SDK. This functionality opens up opportunities for various use cases, including creating digital currencies, loyalty points, and much more. 

 

If you are interested in fungible token development, then connect with our blockchain developers.

Author Yogesh Sahu

Yogesh is a highly experienced backend developer with a strong command over Node.js, MongoDB, Express, and Git/GitHub. He specializes in developing scalable and reliable web applications using JavaScript and Node.js. Additionally he has extensive knowledge of Ethereum, Solidity, and Smart Contracts, and he has worked on various blockchain projects, smart contracts, and implementing various blockchain protocols as well. With a background in backend development, he has built RESTful APIs, implemented authentication and authorization mechanisms, and developed expertise in blockchain technology.

Senior Associate Consultant L1 - Development

bg bg

What's Trending in Tech

bg

Our Offices

India

INDIA

DG-18-009, Tower B,
Emaar Digital Greens, Sector 61,
Gurugram, Haryana
122011.
Unit- 117-120, First Floor,
Welldone Tech Park,
Sector 48, Sohna road,
Gurugram, Haryana
122018.
USA

USA

30N, Gloud St STR E, Sheridan, Wyoming (USA) - 82801
Singapore

SINGAPORE

10 Anson Road, #13-09, International Plaza Singapore 079903.

By using this site, you allow our use of cookies. For more information on the cookies we use and how to delete or block them, please read our cookie notice.