hive-tx v7
GitHub npm

Use

RPC and REST calls

callRPC, callREST, and callWithQuorum send requests to Hive nodes.

callRPC

callRPC sends a JSON-RPC 2.0 request. The function returns the result. The function throws RPCError for a Hive RPC error.

import { callRPC } from 'hive-tx'

const accounts = await callRPC('condenser_api.get_accounts', [['alice']])
const props = await callRPC('condenser_api.get_dynamic_global_properties')

Parameters:

NameDefaultFunction
methodrequiredAPI method name
params[]Array or object
timeoutconfig.timeoutTimeout in milliseconds
retryconfig.retryRetry count after a network failure

If a node does not respond, the library selects the next URL in config.nodes.

Hive API names are in the Hive developer documentation.

callWithQuorum

callWithQuorum sends the same method to more than one node. The function returns a result only if that number of nodes give the same JSON.

import { callWithQuorum } from 'hive-tx'

const accounts = await callWithQuorum(
  'condenser_api.get_accounts',
  [['alice']],
  2
)

The default quorum is 2. The quorum must be less than or equal to config.nodes.length.

Note Quorum is JSON equality. Quorum is not a check of head-block lag. Do not change config.nodes during concurrent calls.

callREST

callREST calls a REST API on config.restNodes. Not all public nodes have REST APIs.

import { callREST } from 'hive-tx'

const balance = await callREST(
  'balance',
  '/accounts/{account-name}/balances',
  { 'account-name': 'alice' }
)

API names:

  • balance
  • hafah
  • hafbe
  • hivemind
  • hivesense
  • reputation
  • nft-tracker
  • hafsql
  • status

A path parameter uses {name} in the path. Other fields become query parameters. TypeScript checks path names for each API.

RPCError

RPCError has message, code, and optional data.