A typed Node.js JSON-RPC client for qbit Core (qbitd), with capability
gating, a chain guard, strict result validation and exact bigint amounts.
No runtime dependencies and no native code.
npm install @qbit-oss/rpc
# or
pnpm add @qbit-oss/rpc
# or
yarn add @qbit-oss/rpc
Requirements:
^22.13.0 || ^24.0.0 || >=26.0.0. CI tests 22.13.0 and the
newest 22.x, 24.x and 26.x on Linux x64; Node.js 27 and later, and other
operating systems, are expected to work but untested.@types/node 22.0.0 or later, which
you install yourself, at the major of your Node.js line. JavaScript needs
neither.The package ships CommonJS and ESM builds with type declarations. See Compatibility for what CI tests.
Read the chain from a testnet4 node on the same machine, in an ES module (for
top-level await):
import { QbitRpcClient, RpcError } from '@qbit-oss/rpc'
const rpc = new QbitRpcClient({
url: 'http://127.0.0.1:48352/', // testnet4's RPC port
auth: { cookieFile: '/home/qbit/.qbit/testnet4/.cookie' },
expectedChain: 'testnet4',
})
const info = await rpc.getBlockchainInfo()
console.log(info.chain, info.blocks, info.bestBlockHash)
try {
await rpc.getBlockHash(info.blocks + 1) // past the tip
} catch (error) {
// The node's own answer, typed, with its JSON-RPC code: -8 Block height out of range
if (RpcError.is(error)) console.log(error.rpcCode, error.message)
else throw error
}
Reads need no capability. Calls that sign, broadcast, mine or administer a
wallet need one enabled in capabilities, and await rpc.confirmChain()
first. A worked payout, from funding a PSBT to broadcasting it, is in
Payments.
call() for the other allowlisted methods, and batch()
for many reads in one round trip.
Methodswallet-read, wallet-write,
broadcast, mining, wallet-admin or node-admin. Methods that sign and
broadcast in one step are never allowed; extraMethods opens others under a
stated policy.
CapabilitiesX.is(error) across the CommonJS and ESM builds. A side-effecting call that
may have run rejects with RpcUnknownOutcomeError, which carries what you
need to reconcile, such as the txid; any other rejection is definite.
ErrorsAbortSignal, opt-in retries for reads only, and a limit on each
client's open requests, to stay within qbitd's work queue.
Configurationbigint bits, parsed from the reply's text,
never a JavaScript number.
AmountswalletProcessPsbt first counts the
signatures a PSBT needs from each PQC key, and signs nothing when an
exhausted key, or one that would run out partway, would leave it half signed.
Paymentscall(). sendmany, sendtoaddress, send, sendall and bumpfee
cannot be opened at all, as they sign and broadcast in one step.The full list is in Limits.
@qbit-oss/zmq@qbit-oss/zmq, for block
and mempool notifications@qbit-oss/payments handles key budgets, fee caps and
crash-safe sending;
Payments
shows the raw calls