← Protocols
Hedera
01Description

Hedera is a public DLT secured by the hashgraph consensus algorithm. It exposes three native services — Hedera Token Service (HTS) for fungible/non-fungible tokens without smart contracts, Hedera Consensus Service (HCS) for ordered messages, and Hedera Smart Contract Service (HSCS, EVM-compatible) — plus a JSON-RPC relay that lets EVM tooling target Hedera. `@hashgraph/sdk` is the official TS/JS SDK; HashConnect (and WalletConnect v2) handle wallet pairing for HashPack and Blade.

02Best for
  • 01Hedera dapps using HTS (native tokens, no Solidity required)
  • 02Hedera Consensus Service for ordered audit logs / messaging
  • 03EVM contract deployments via the Hedera JSON-RPC relay
  • 04HashPack / Blade wallet auth via HashConnect
  • 05low-fixed-fee, high-throughput payment apps
03Install
  • pnpm add @hashgraph/sdk @hashgraph/hedera-wallet-connect
04Environment variables
VariableScopeDescription
NEXT_PUBLIC_HEDERA_NETWORKClient`mainnet`, `testnet`, or `previewnet` — selects mirror node and consensus nodes.
HEDERA_OPERATOR_IDServerOperator account ID in `0.0.x` form used to pay fees server-side (e.g. 0.0.12345).
HEDERA_OPERATOR_KEYServerOperator account ED25519 / ECDSA private key (DER-encoded hex). Server-side only — never ship to the client.
NEXT_PUBLIC_HEDERA_JSON_RPC_URLClientOptional EVM JSON-RPC relay URL (e.g. https://mainnet.hashio.io/api) for using viem/ethers against HSCS.
05Prompt snippet
Use `@hashgraph/sdk`. Build a client server-side with `Client.forMainnet().setOperator(AccountId.fromString(process.env.HEDERA_OPERATOR_ID!), PrivateKey.fromStringED25519(process.env.HEDERA_OPERATOR_KEY!))`. Mint a native token via Hedera Token Service: `const tx = await new TokenCreateTransaction().setTokenName('Demo').setTokenSymbol('DMO').setTokenType(TokenType.FungibleCommon).setInitialSupply(1000).setTreasuryAccountId(operatorId).execute(client); const receipt = await tx.getReceipt(client); const tokenId = receipt.tokenId;`. Transfer with `TransferTransaction().addTokenTransfer(tokenId, from, -100).addTokenTransfer(tokenId, to, 100)`. For dapp UX use `@hashgraph/hedera-wallet-connect` (WalletConnect v2) — the user's wallet returns a `DAppSigner` you pass to `tx.freezeWithSigner(signer)` then `tx.executeWithSigner(signer)`. For EVM contracts, point viem/ethers at the JSON-RPC relay; `accountId.toSolidityAddress()` converts `0.0.x` IDs to EVM addresses.
06Gotchas
  • Hedera uses two account ID formats: native `0.0.x` (shard.realm.num) and EVM-style `0x…` (long-zero or aliased). HTS calls expect `AccountId`; EVM contracts expect `address` — converting requires `AccountId.fromString('0.0.x').toSolidityAddress()` or `AccountId.fromEvmAddress(0,0,'0x…')`.
  • Token associations are mandatory: an account cannot receive an HTS token until it signs a `TokenAssociateTransaction` for that token (or the token has unlimited auto-associations). Sending to an unassociated account fails with `TOKEN_NOT_ASSOCIATED_TO_ACCOUNT`.
  • Fees are paid in HBAR but priced in USD and recalculated per network exchange rate; underestimating `setMaxTransactionFee` causes `INSUFFICIENT_TX_FEE`. State-changing operations also charge a per-byte storage cost.
  • Two SDKs of dramatically different shape exist: the JS SDK (`@hashgraph/sdk`) is async/builder-style; the EVM JSON-RPC relay exposes a partial Ethereum API where `eth_getLogs`, `eth_subscribe`, and historical state queries can be missing or rate-limited.
  • Mirror node vs consensus node split: state-changing txs go to consensus nodes (`Client`), but reads (history, balances, mirror queries) go to mirror nodes (`MirrorClient` / REST API). Querying balance via the consensus node API works but is expensive — use the mirror node for reads.
  • Private keys come in three flavors (ED25519, ECDSA secp256k1, and legacy DER) — ECDSA is required for any account that must hold an EVM-compatible alias. Generating ED25519 and expecting EVM compatibility silently breaks contract calls.
  • HCS topic submit messages are ordered globally but max 1024 bytes per message (or chunked) and have a transient ~3–5s consensus latency before they appear in the mirror node.
07Alternatives