Skip to main content

Overview

The config object allows you to customize the behavior of the hive-tx library, including API node endpoints, timeout settings, retry attempts, and blockchain-specific parameters.

Configuration Object

nodes
string[]
Array of Hive API node endpoints for load balancing and failover. The library will attempt to connect to these nodes in order when making API calls.Default:
[
  'https://api.hive.blog',
  'https://api.deathwing.me',
  'https://api.openhive.network',
  'https://rpc.mahdiyari.info',
  'https://techcoderx.com',
  'https://hiveapi.actifit.io',
  'https://api.c0ff33a.uk'
]
restNodes
string[]
Array of Hive API node endpoints that support REST APIs. Note: URLs should not include a trailing slash.Default:
[
  'https://api.hive.blog',
  'https://rpc.mahdiyari.info',
  'https://techcoderx.com',
  'https://hiveapi.actifit.io',
  'https://api.c0ff33a.uk'
]
chain_id
string
The Hive blockchain chain ID used for transaction signing and verification.Default: 'beeab0de00000000000000000000000000000000000000000000000000000000' (Mainnet)
address_prefix
string
Address prefix used for public key formatting.Default: 'STM' (for Hive mainnet)
timeout
number
Timeout in milliseconds for individual API calls. If an API call takes longer than this duration, it will be aborted and potentially retried.Default: 10000 (10 seconds)
retry
number
Number of retry attempts for failed API calls before throwing an error. The library will try different nodes from the nodes array on each retry.Default: 8

Usage Examples

Modify Timeout and Retry Settings

import { config } from 'hive-tx'

// Increase timeout for slower connections
config.timeout = 20000 // 20 seconds

// Reduce retry attempts for faster failures
config.retry = 3

Use Custom Nodes

import { config } from 'hive-tx'

// Add your own node to the beginning of the list
config.nodes = [
  'https://my-custom-node.com',
  ...config.nodes
]

// Or replace all nodes with your own
config.nodes = [
  'https://my-node-1.com',
  'https://my-node-2.com'
]

Configure for Testnet

import { config } from 'hive-tx'

// Configure for Hive testnet
config.nodes = ['https://testnet.openhive.network']
config.restNodes = ['https://testnet.openhive.network']
config.chain_id = '18dcf0a285365fc58b71f18b3d3fec954aa0c141c44e4e5cb4cf777b9eab274e'
config.address_prefix = 'TST'

Optimize for Performance

import { config } from 'hive-tx'

// Reduce timeout and retries for faster failures in high-speed apps
config.timeout = 5000   // 5 seconds
config.retry = 3        // Only 3 retries

// Use only the fastest nodes
config.nodes = [
  'https://api.hive.blog',
  'https://api.deathwing.me'
]

Configure REST Nodes

import { config } from 'hive-tx'

// Add custom REST API nodes
config.restNodes = [
  'https://my-rest-node.com',
  ...config.restNodes
]

Important Notes

  • Configuration changes affect all subsequent API calls and transactions
  • Always modify the configuration before making any API calls or creating transactions
  • The library will automatically cycle through available nodes if one fails
  • REST nodes must support the Hive REST API format (without trailing slash)
  • For production applications, consider using multiple reliable nodes for better failover

Build docs developers (and LLMs) love