> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/mahdiyari/hive-tx/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuration

> Customize hive-tx behavior with node configuration, timeouts, and network settings

hive-tx uses a global configuration object to manage API nodes, network settings, and request behavior. You can customize these settings to use your own nodes, adjust timeouts, or configure for different Hive networks.

## Configuration Object

The configuration is exported from the main package:

```typescript theme={null}
import { config } from 'hive-tx'

console.log(config.nodes)      // Array of API endpoints
console.log(config.chain_id)   // Blockchain identifier
console.log(config.timeout)    // Request timeout in ms
```

All settings can be modified at runtime:

```typescript theme={null}
config.timeout = 15_000  // Increase timeout to 15 seconds
config.retry = 5         // Reduce retry attempts
```

## API Nodes

hive-tx uses multiple Hive API nodes for load balancing and automatic failover.

### Default Nodes

```typescript src/config.ts:10 theme={null}
config.nodes = [
  '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'
]
```

When an API call fails, hive-tx automatically tries the next node in the list.

### Custom Nodes

Replace the node list with your own infrastructure:

```typescript theme={null}
import { config } from 'hive-tx'

// Use only your nodes
config.nodes = [
  'https://my-hive-node.example.com',
  'https://backup-node.example.com'
]
```

### Add Nodes

Append additional nodes while keeping defaults:

```typescript theme={null}
config.nodes.push('https://my-custom-node.com')
```

<Tip>
  Using multiple nodes improves reliability. If one node is down or slow, requests automatically failover to the next available node.
</Tip>

## REST API Nodes

Some operations use REST APIs instead of JSON-RPC. These nodes support the REST endpoints:

```typescript src/config.ts:24 theme={null}
config.restNodes = [
  'https://api.hive.blog',
  'https://rpc.mahdiyari.info',
  'https://techcoderx.com',
  'https://hiveapi.actifit.io',
  'https://api.c0ff33a.uk'
]
```

<Info>
  REST nodes are used for specific API methods like transaction status checks. They're separate from the main RPC nodes.
</Info>

### Configure REST Nodes

```typescript theme={null}
import { config } from 'hive-tx'

config.restNodes = [
  'https://my-rest-node.example.com'
]
```

<Warning>
  REST node URLs should **not** have a trailing slash. For example, use `https://api.hive.blog` not `https://api.hive.blog/`.
</Warning>

## Network Configuration

### Chain ID

The chain ID ensures transactions are valid only on the intended network:

```typescript src/config.ts:36 theme={null}
config.chain_id = 'beeab0de00000000000000000000000000000000000000000000000000000000'
```

This is Hive mainnet's chain ID. For testnet:

```typescript theme={null}
// Hive testnet chain ID
config.chain_id = '18dcf0a285365fc58b71f18b3d3fec954aa0c141c44e4e5cb4cf777b9eab274e'
```

### Address Prefix

The prefix used for public key formatting:

```typescript src/config.ts:42 theme={null}
config.address_prefix = 'STM'
```

For testnet:

```typescript theme={null}
config.address_prefix = 'TST'
```

This affects how public keys are displayed:

* Mainnet: `STM8m5UgaFAAYQRuaNejYdS8FVLVp9Ss3K1qAVk5de6F8s3HnVbvA`
* Testnet: `TST8m5UgaFAAYQRuaNejYdS8FVLVp9Ss3K1qAVk5de6F8s3HnVbvA`

## Timeout and Retry Settings

### Request Timeout

Maximum time to wait for an API response:

```typescript src/config.ts:48 theme={null}
config.timeout = 10_000  // 10 seconds
```

Increase for slow networks:

```typescript theme={null}
config.timeout = 30_000  // 30 seconds
```

<Info>
  Timeout is in **milliseconds**. Default is 10,000ms (10 seconds).
</Info>

### Retry Attempts

Number of retry attempts before failing:

```typescript src/config.ts:54 theme={null}
config.retry = 8  // Try up to 8 times
```

With 8 retries and multiple nodes, hive-tx will:

1. Try first node
2. On failure, try second node
3. Continue through all nodes
4. Repeat up to 8 total attempts

Reduce retries for faster failure:

```typescript theme={null}
config.retry = 3  // Fail faster
```

## Complete Configuration

Here's the full default configuration:

```typescript src/config.ts:5 theme={null}
export const config = {
  nodes: [
    '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: [
    'https://api.hive.blog',
    'https://rpc.mahdiyari.info',
    'https://techcoderx.com',
    'https://hiveapi.actifit.io',
    'https://api.c0ff33a.uk'
  ],
  
  chain_id: 'beeab0de00000000000000000000000000000000000000000000000000000000',
  address_prefix: 'STM',
  timeout: 10_000,
  retry: 8
}
```

## Use Cases

### Custom Node Setup

Use your own Hive node infrastructure:

```typescript theme={null}
import { config } from 'hive-tx'

// Production setup with your nodes
config.nodes = [
  'https://hive-1.mycompany.com',
  'https://hive-2.mycompany.com',
  'https://hive-3.mycompany.com'
]

config.restNodes = [
  'https://hive-rest.mycompany.com'
]

config.timeout = 15_000
config.retry = 5
```

### Testnet Configuration

Switch to Hive testnet:

```typescript theme={null}
import { config } from 'hive-tx'

// Testnet settings
config.nodes = [
  'https://testnet.openhive.network'
]

config.restNodes = [
  'https://testnet.openhive.network'
]

config.chain_id = '18dcf0a285365fc58b71f18b3d3fec954aa0c141c44e4e5cb4cf777b9eab274e'
config.address_prefix = 'TST'
```

### Development Mode

Faster failures during development:

```typescript theme={null}
import { config } from 'hive-tx'

// Quick failures for development
config.timeout = 5_000   // 5 second timeout
config.retry = 2         // Only retry once

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

### Production Reliability

Maximize reliability for production:

```typescript theme={null}
import { config } from 'hive-tx'

// Production reliability
config.timeout = 20_000  // Longer timeout
config.retry = 12        // More retries

// All available nodes
config.nodes = [
  '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',
  'https://my-backup.example.com'  // Your backup node
]
```

## Node Failover

hive-tx automatically handles node failures:

1. **Request sent** to first node in `config.nodes`
2. **Timeout or error** occurs
3. **Retry with next node** in the list
4. **Continue** until success or all retries exhausted

```typescript theme={null}
// Example failover sequence:
// 1. Try api.hive.blog
// 2. Timeout → Try api.deathwing.me
// 3. Error → Try api.openhive.network
// 4. Success → Return result
```

<Tip>
  Failover is automatic and transparent. Your code doesn't need to handle node failures - hive-tx does it for you.
</Tip>

## Environment-Based Configuration

Use environment variables to configure nodes:

```typescript theme={null}
import { config } from 'hive-tx'

// Configure from environment
if (process.env.HIVE_NODES) {
  config.nodes = process.env.HIVE_NODES.split(',')
}

if (process.env.HIVE_CHAIN_ID) {
  config.chain_id = process.env.HIVE_CHAIN_ID
}

if (process.env.HIVE_TIMEOUT) {
  config.timeout = parseInt(process.env.HIVE_TIMEOUT)
}
```

Then in your `.env` file:

```bash theme={null}
HIVE_NODES=https://node1.example.com,https://node2.example.com
HIVE_CHAIN_ID=beeab0de00000000000000000000000000000000000000000000000000000000
HIVE_TIMEOUT=15000
```

## TypeScript Types

The configuration object has full TypeScript support:

```typescript theme={null}
interface Config {
  nodes: string[]
  restNodes: string[]
  chain_id: string
  address_prefix: string
  timeout: number
  retry: number
}
```

TypeScript will warn if you set invalid values:

```typescript theme={null}
config.timeout = '5000'  // ❌ Error: Type 'string' is not assignable to type 'number'
config.timeout = 5000    // ✅ Correct
```

## Best Practices

<AccordionGroup>
  <Accordion title="Node Selection">
    * Use at least 3 nodes for reliability
    * Include geographically diverse nodes
    * Test nodes before adding to production config
    * Monitor node performance and remove slow/unreliable nodes
  </Accordion>

  <Accordion title="Timeout Configuration">
    * Use shorter timeouts (5-10s) for interactive apps
    * Use longer timeouts (15-30s) for background tasks
    * Consider network conditions of your users
    * Balance between responsiveness and reliability
  </Accordion>

  <Accordion title="Retry Strategy">
    * More retries = higher reliability but slower failures
    * Fewer retries = faster failures but less resilient
    * Consider exponential backoff for custom retry logic
    * Log retry attempts for debugging
  </Accordion>

  <Accordion title="Network Configuration">
    * Never mix mainnet and testnet chain IDs
    * Verify chain ID matches your target network
    * Use environment variables for different environments
    * Document which network your app targets
  </Accordion>
</AccordionGroup>

## Troubleshooting

### All Nodes Failing

```typescript theme={null}
// Increase timeout and retries
config.timeout = 30_000
config.retry = 15

// Add more nodes
config.nodes.push('https://another-node.com')
```

### Slow Response Times

```typescript theme={null}
// Use only fast nodes
config.nodes = [
  'https://api.hive.blog',
  'https://api.deathwing.me'
]

// Reduce timeout for faster failures
config.timeout = 5_000
```

### Wrong Network Errors

```typescript theme={null}
// Verify chain ID matches network
console.log(config.chain_id)

// Mainnet:
config.chain_id = 'beeab0de00000000000000000000000000000000000000000000000000000000'

// Testnet:
config.chain_id = '18dcf0a285365fc58b71f18b3d3fec954aa0c141c44e4e5cb4cf777b9eab274e'
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Transactions" icon="file-contract" href="/concepts/transactions">
    Create and broadcast transactions
  </Card>

  <Card title="API Methods" icon="code" href="/api/call-rpc">
    Call Hive API methods
  </Card>

  <Card title="API Calls Guide" icon="network-wired" href="/guides/api-calls">
    Learn how to make API calls
  </Card>

  <Card title="Transaction Guide" icon="triangle-exclamation" href="/guides/creating-transactions">
    Create and broadcast transactions
  </Card>
</CardGroup>
