Skip to content

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

 
 

Latest commit

 

History

789 Commits

Folders and files

Repository files navigation

Hiero Enterprise JS

CI TCK Coverage OpenSSF Scorecard License

TypeScript libraries for building apps on Hiero networks: Node.js services, browser apps and React Native apps.

@hiero-hackers/enterprise-core sends transactions: accounts, tokens, topics, files, smart contracts and schedules, each behind a typed service. @hiero-hackers/enterprise-mirror reads the network's history from the mirror node, with no dependencies and no keys. Both wrap the plumbing a production service needs around the Hiero SDK: a shared client, input checks, typed errors, pagination and rate limiting.

Install

This repository publishes two packages. Both run on Node.js 18 or later, in browsers and in React Native.

Core, to send transactions. It uses the app's own Hiero SDK (a peer dependency), so install both:

npm install @hiero-hackers/enterprise-core @hiero-ledger/sdk

Mirror, to read from the mirror node:

npm install @hiero-hackers/enterprise-mirror

Use them together or on their own.

Browsers and React Native

Package Node.js 18+ Browsers React Native
enterprise-core ✓ gRPC ✓ gRPC-web, through the SDK's WebClient ✓ gRPC-web, through the SDK's NativeClient, with react-native-get-random-values
enterprise-mirror ✓ fetch ✓ fetch ✓ fetch
  • Each package ships one ESM and one CommonJS build for every platform. Core leaves @hiero-ledger/sdk to your app, so your bundler picks the SDK's own browser or React Native build.
  • Environment variables are read only on Node.js. Elsewhere, pass a config object: new HieroContext({ ... }) or createMirrorNodeClient({ ... }).
  • Custom and local networks need gRPC-web proxies for the consensus nodes; mainnet, testnet and previewnet have them built in.
  • Users can read code that runs in their browser or on their phone, so don't put an operator private key there. Core can sign through a wallet, KMS or backend instead, with operatorPublicKey and operatorSigner.

The core and mirror READMEs have the setup, and samples has a Vite app and an Expo app.

Usage

Core

Writes need an operator account to sign and pay the fee. On testnet you can create one for free in the Hedera Developer Portal. Set it in the environment:

HIERO_NETWORK=testnet
HIERO_OPERATOR_ID=0.0.12345
HIERO_OPERATOR_KEY=<your private key>
HIERO_OPERATOR_KEY_TYPE=ecdsa   # or ed25519, or der

Create a topic and post a message to it:

import { HieroContext, TopicService } from "@hiero-hackers/enterprise-core";

const context = new HieroContext(); // reads the HIERO_* variables
const topics = new TopicService(context);

const { topicId } = await topics.createTopic({ topicMemo: "order events" });
const { sequenceNumber } = await topics.submitMessage({
  topicId,
  message: "order 42 shipped",
});

console.log(`message ${sequenceNumber} on topic ${topicId}`);
context.close();
message 1 on topic 0.0.5005123

In a server, create the context and services once at startup and call context.close() on shutdown.

Mirror

Reads need no account:

import {
  AccountRepository,
  createMirrorNodeClient,
  tinybarToHbarExact,
} from "@hiero-hackers/enterprise-mirror";

const mirror = createMirrorNodeClient({ network: "mainnet" });
const account = await new AccountRepository(mirror).findByAccountId("0.0.800");

console.log(`${account.accountId} holds ${tinybarToHbarExact(account.balance)} ℏ`);
0.0.800 holds 133361877.79077463 ℏ

Architecture

Your application uses enterprise-core to send signed transactions to the consensus nodes over gRPC, and enterprise-mirror to read history from the mirror node over REST. The consensus nodes stream their records to the mirror node.

A Hiero network has two kinds of servers:

  • Consensus nodes order and execute transactions. enterprise-core talks to them through the SDK. Every transaction is validated, built, signed by the operator, submitted, and returns its receipt.
  • Mirror nodes store the history and serve it through a free REST API. enterprise-mirror is a typed client for that API.

What It Does

Core — one service per part of the network:

Service Covers
AccountService Accounts, HBAR / token / NFT transfers, allowances, balances, signature checks
TokenService Fungible tokens and NFTs: create, mint, burn, freeze, pause, KYC, fees, airdrops
TopicService Topics: create, update, delete, submit messages, subscribe
FileService Files: create, append, update, delete, read
ContractService Smart contracts: deploy, execute, update, delete, read-only calls, gas estimates, hook storage
ScheduleService Scheduled transactions: sign, cancel, inspect
NetworkService Transaction receipts and records, network version, atomic batches
  • Input is checked before sending. Bad input fails with INPUT_INVALID and costs no fee.
  • Many write methods have a schedule… version, so several keys can sign the same transaction.
  • Listeners get an event before and after every transaction and consensus node query, for logs and metrics.

Mirror — the whole mirror node REST API:

  • Repositories for accounts, tokens, NFTs, topics, transactions, contracts, blocks, schedules and network state
  • Every list returns a Page with next(); collectAll and paginate read all pages
  • Client-side rate limiting and retries
  • Large numbers keep their full precision
  • Helpers for tinybar ⇄ ℏ, token decimals and consensus timestamps

The core and mirror READMEs list every export. samples/examples has a runnable script for each service, and samples has Express, Fastify and NestJS servers, a Vite browser app and an Expo React Native app.

API Reference

The API reference for both packages is generated from the source comments with TypeDoc. It lists every exported service, repository, option and result type, with each method's parameters, return value, errors and, for many methods, a code example. Build it locally and open docs/api/index.html:

pnpm install
pnpm run docs

Errors

Core throws HieroError and mirror throws MirrorError. Both have a code you can check:

import {
  AccountService,
  HieroContext,
  HieroError,
  HieroErrorCodes,
} from "@hiero-hackers/enterprise-core";

const context = new HieroContext();
const accounts = new AccountService(context);

try {
  await accounts.transferHbar("0.0.1234", 5, context.operatorAccountId);
} catch (err) {
  if (err instanceof HieroError && err.code === HieroErrorCodes.InputInvalid) {
    // Rejected before sending; no fee was charged.
  }
  throw err;
}

Limitations

  • Pre-1.0. Minor releases can break the API.
  • Browsers and React Native are only checked by bundling. CI runs the tests on Node.js 22 and 24, and bundles both packages for browsers and React Native without running them there.
  • Not every SDK feature is wrapped. Batch transactions, hooks and fee estimates are on the roadmap. Until then, context.client gives you the SDK client directly.

Contributing

Contributions welcome. See CONTRIBUTING.md to get started, or open an issue to ask a question. Maintainers release with RELEASE.md.

License

Apache-2.0 — see LICENSE

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages