Getting Started
firo-rpc is a TypeScript library that lets you talk to a Firo node from your application. You send requests — like "what's the current block count?" or "send some FIRO to this address" — and it gives you back typed, structured responses.
Install
npm install @nexusocean/firo-rpc
Connect to a Node
Before using any methods you need to create a client. The client holds your connection settings and is reused for every call.
import { createFiroRpcClient } from '@nexusocean/firo-rpc';
const client = createFiroRpcClient({
host: '127.0.0.1',
port: 8888,
user: 'rpcuser',
pass: 'rpcpass',
protocol: 'http',
});
| Option | Default | Description |
|---|---|---|
host | 127.0.0.1 | IP or hostname of your Firo node |
port | 8888 | RPC port configured in firo.conf |
user | — | RPC username (required) |
pass | — | RPC password (required) |
protocol | http | Use https if your node has TLS enabled |
timeout | — | Request timeout in milliseconds |
Make Your First Call
const blockCount = await client.getBlockCount();
console.log(`Chain is at block ${blockCount}`);
Batch Multiple Calls
Send several requests in one round trip using client.batch. This is faster than making individual calls one after another.
const results = await client.batch([
{ method: 'getblockcount' },
{ method: 'getnetworkinfo' },
]);
const count = results[0].result as number;
const info = results[1].result;
Call Any Method Directly
If a method isn't listed in the typed API, you can still call it using the generic client.call escape hatch:
const raw = await client.call<string>('getbestblockhash');
Node Requirements
Some methods require extra flags in your firo.conf file:
| Flag | Needed for |
|---|---|
txindex=1 | Looking up transactions not in your wallet or mempool |
addressindex=1 | getAddressBalance, getAddressTxIds |
mobile=1 | All Spark privacy methods |
After adding index flags, restart your node with -reindex once to build the index from scratch.