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:
| Name | Default | Function |
|---|---|---|
method | required | API method name |
params | [] | Array or object |
timeout | config.timeout | Timeout in milliseconds |
retry | config.retry | Retry 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.
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:
balancehafahhafbehivemindhivesensereputationnft-trackerhafsqlstatus
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.