JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9
  • Score
    100M100P100Q50737F
  • License MIT

Typescript Hedera Mirror Node Rest API wrapper with complete declarative abstraction layer

Package Exports

  • @tikz/hedera-mirror-node-ts
  • @tikz/hedera-mirror-node-ts/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@tikz/hedera-mirror-node-ts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Typescript Hedera Mirror Node Rest API wrapper with complete declarative abstraction layer

Features

  • Typed Library
  • Typed Responses
  • Flexible with different http clients like axios, fetch etc
  • No need to remember how and what params exist for different resources in raw form
  • Easily maintainable

Getting Started

Installation

npm

npm install @tikz/hedera-mirror-node-ts

yarn

yarn add @tikz/hedera-mirror-node-ts

Initialize

Client needs to be initialized with base url depending upon network. BaseURL should not contain forward slashes at end

import { Client } from "@tikz/hedera-mirror-node-ts";
/**
* https://previewnet.mirrornode.hedera.com
* https://mainnet-public.mirrornode.hedera.com
*/
const client = new Client(baseURL)

Usage

Get Topic Messages

import { Client, topicMessages, optionalFilters } from "@tikz/hedera-mirror-node-ts";

const client = new Client('https://testnet.mirrornode.hedera.com')
const msgCursor = topicMessages(client)
  .setTopicId('0.0.16430')
  .setLimit(10)
  .order('asc')
  .sequenceNumber(optionalFilters.greaterThan(20))

// get initial data
// -> 20 < sequenceNumber <= 30
const msgs = await msgCursor.get() 

// get next set of data
// -> 30 < sequenceNumber <= 40
const msgs2 = await msgCursor.next() 

// get next set of data
// -> 40 < sequenceNumber <= 50
const msgs3 = await msgCursor.next() 

Refer TopicMessages for full api

Get Accounts

import { accounts, optionalFilters } from "@tikz/hedera-mirror-node-ts";
const accountCursor = accounts(client)
  .setAccountId(optionalFilters.lessThan('0.0.15678177'))
  .setLimit(2)
const accounts1 = await accountCursor.get()
const accounts2 = await accountCursor.next()

Refer Accounts for full api

Get Transactions

import { transactions, optionalFilters, TransactionType } from "@tikz/hedera-mirror-node-ts";

const transactionCursor = transactions(client)
  .setAccountId('0.0.15678177')
  .setLimit(2)
  .setType('debit')
  .setTransactionType(TransactionType.CONSENSUSSUBMITMESSAGE)
  .setResult('success')
const txns = await transactionCursor.get()
// get next batch of transactions
const txns2 = await transactionCursor.next()

Refer Transactions for full api

Network Supply

import { networkSupply } from "@tikz/hedera-mirror-node-ts";
const supply = await networkSupply(client).get()

Refer NetworkSupply for full api

Using different client

By default axios is used to make requests which can be easily changed

import { BaseMirrorClient } from "@tikz/hedera-mirror-node-ts";

// Client.ts
class AxiosClient implements BaseMirrorClient{
  public baseURL = 'https://mainnet-public.mirrornode.hedera.com'
  public async fetch<D>(url:string,params:Params):Promise<D>{
    const response = await axios.get(baseURL,{url,url:params:params})
    return response.data
  }
}
// index.ts
const client = new AxiosClient()

Migrating from deprecated versions

When /api/v1 gets deprecated then a more raw approach can be used till library gets updated

import { Client, TopicMessages,Transactions ,optionalFilters } from "@tikz/hedera-mirror-node-ts";

const client = new Client('https://testnet.mirrornode.hedera.com')

const msgCursor = new TopicMessages(client,'/api/v2/topics')
  .setTopicId('0.0.16430')
  .setLimit(10)
  .order('asc')
  .sequenceNumber(optionalFilters.greaterThan(20))
// similarly
const transactionCursor = new Transactions(client,'/api/v1/transactions')

References

TopicMessages

interface ConsensusParams {
  [filterKeys.SEQUENCE_NUMBER]: OptionalFilters;
}
// Methods
sequenceNumber(val: ConsensusParams['sequencenumber']): TopicMessages;
setTopicId(val: string): TopicMessages;
get(): Promise<MessagesResponse>;
next(): Promise<MessagesResponse>;

Accounts

interface AccountParams {
  [filterKeys.TRANSACTION_TYPE]: TransactionType;
  [filterKeys.ACCOUNT_ID]: string;
  [filterKeys.ACCOUNT_PUBLICKEY]: OptionalFilters;
  [filterKeys.ACCOUNT_BALANCE]: OptionalFilters;
}
// Methods
setBalance(val: AccountParams['account.balance']): Accounts;
setAccountId(val: AccountParams['account.id']): Accounts;
setPublicKey(val: AccountParams['account.publickey']): Accounts;
setTransactionType(val: AccountParams['transactiontype']): Accounts;
get(): Promise<AccountsResponse>;
next(): Promise<AccountsResponse>;

Transactions

interface TransactionParams {
  [filterKeys.TRANSACTION_TYPE]: TransactionType; 
  [filterKeys.ACCOUNT_ID]: string;
  [filterKeys.RESULT]: 'fail' | 'success';
  [filterKeys.CREDIT_TYPE]: 'credit' | 'debit';
}
// Methods 
setAccountId(val: OptionalFilters): Transaction;
setResult(val: TransactionParams['result']): Transaction;
setType(val: TransactionParams['type']): Transaction;
setTransactionType(val: TransactionParams['transactiontype']): Transaction;
get(): Promise<TransactionsResponse>;
next(): Promise<TransactionsResponse>;

NetworkSupply

// Methods
get(): Promise<NetworkSupplyResponse>;
// Response
interface NetworkSupplyResponse {
  released_supply: string;
  timestamp: string;
  total_supply: string;
}

Order

type Order = "asc" | "desc"

OptionalFilters

// optionalFilters is a helper provided in package for navigating cursors
type OptionalFilters = `gt:${string}` | `gte:${string}` | `lt:${string}` | `lte:${string}` | string;
const optionalFilters: {
  greaterThan(val: any): OptionalFilters;
  greaterThanEqualTo(val: any): OptionalFilters;
  lessThan(val: any): OptionalFilters;
  lessThanEqualTo(val: any): OptionalFilters;
};

TransactionType

enum TransactionType {
    CONSENSUSCREATETOPIC = "CONSENSUSCREATETOPIC",
    CONSENSUSDELETETOPIC = "CONSENSUSDELETETOPIC",
    CONSENSUSSUBMITMESSAGE = "CONSENSUSSUBMITMESSAGE",
    CONSENSUSUPDATETOPIC = "CONSENSUSUPDATETOPIC",
    CONTRACTCALL = "CONTRACTCALL",
    CONTRACTCREATEINSTANCE = "CONTRACTCREATEINSTANCE",
    CONTRACTDELETEINSTANCE = "CONTRACTDELETEINSTANCE",
    CONTRACTUPDATEINSTANCE = "CONTRACTUPDATEINSTANCE",
    CRYPTOADDLIVEHASH = "CRYPTOADDLIVEHASH",
    CRYPTOCREATEACCOUNT = "CRYPTOCREATEACCOUNT",
    CRYPTODELETE = "CRYPTODELETE",
    CRYPTODELETELIVEHASH = "CRYPTODELETELIVEHASH",
    CRYPTOTRANSFER = "CRYPTOTRANSFER",
    CRYPTOUPDATEACCOUNT = "CRYPTOUPDATEACCOUNT",
    FILEAPPEND = "FILEAPPEND",
    FILECREATE = "FILECREATE",
    FILEDELETE = "FILEDELETE",
    FILEUPDATE = "FILEUPDATE",
    FREEZE = "FREEZE",
    SCHEDULECREATE = "SCHEDULECREATE",
    SCHEDULEDELETE = "SCHEDULEDELETE",
    SCHEDULESIGN = "SCHEDULESIGN",
    SYSTEMDELETE = "SYSTEMDELETE",
    SYSTEMUNDELETE = "SYSTEMUNDELETE",
    TOKENASSOCIATE = "TOKENASSOCIATE",
    TOKENBURN = "TOKENBURN",
    TOKENCREATION = "TOKENCREATION",
    TOKENDELETION = "TOKENDELETION",
    TOKENDISSOCIATE = "TOKENDISSOCIATE",
    TOKENFEESCHEDULEUPDATE = "TOKENFEESCHEDULEUPDATE",
    TOKENFREEZE = "TOKENFREEZE",
    TOKENGRANTKYC = "TOKENGRANTKYC",
    TOKENMINT = "TOKENMINT",
    TOKENPAUSE = "TOKENPAUSE",
    TOKENREVOKEKYC = "TOKENREVOKEKYC",
    TOKENUNFREEZE = "TOKENUNFREEZE",
    TOKENUNPAUSE = "TOKENUNPAUSE",
    TOKENUPDATE = "TOKENUPDATE",
    TOKENWIPE = "TOKENWIPE",
    UNCHECKEDSUBMIT = "UNCHECKEDSUBMIT"
}