qbit-rpc
    Preparing search index...

    Module @qbit-oss/rpc

    @qbit-oss/rpc

    npm: @qbit-oss/rpc CI License: MIT

    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:

    • Node.js ^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.
    • qbit Core 1.0.x releases: 1.0.0 and any later 1.0 patch release, but no pre-release. Tested against v1.0.1.
    • TypeScript 5.0 or later, with @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.

    • Typed calls. Typed methods for chain, mempool, wallet, mining and wallet-admin calls, each reply validated field by field and returned with camelCase names; call() for the other allowlisted methods, and batch() for many reads in one round trip. Methods
    • Capabilities and the allowlist. Every method is on an allowlist under a capability the client opts into: wallet-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. Capabilities
    • Chain guard. A call that changes state goes out only once the node's chain name, genesis block hash, signet challenge and qbit Core version have been checked, and the check is repeated when it goes stale. Chain guard
    • Error model. Every failure is a typed error, recognized with X.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. Errors
    • Timeouts and retries. One deadline per call over every wait and attempt, an AbortSignal, opt-in retries for reads only, and a limit on each client's open requests, to stay within qbitd's work queue. Configuration
    • TLS for remote nodes. Credentials go in cleartext only to loopback. A remote node is reached through a TLS terminator, with a private CA, a client certificate and key pins, directly or through a proxy. Remote nodes
    • Exact amounts. Amounts are bigint bits, parsed from the reply's text, never a JavaScript number. Amounts
    • PQC keys checked before signing. walletProcessPsbt 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. Payments
    • Wallet workflows. PSBT payouts, PQC signature budgets, fee bumps, CPFP packages, wallet administration and mining. Wallet, Mining
    • Node.js only: it does not run in a browser.
    • The typed methods cover a chosen set; other methods are untyped through call(). sendmany, sendtoaddress, send, sendall and bumpfee cannot be opened at all, as they sign and broadcast in one step.
    • The chain guard cannot tell two regtest nodes apart, or two nodes of the same chain behind one URL.

    The full list is in Limits.

    • Documentation and the API report, every export and its declaration
    • API reference: every export and member, with its doc comment
    • Examples: a payout, a deposit watcher and a header walk, which CI compiles against the packed package
    • Changelog, shared with @qbit-oss/zmq
    • Security: the review status, and how to report a vulnerability
    • @qbit-oss/zmq, for block and mempool notifications
    • For payouts, @qbit-oss/payments handles key budgets, fee caps and crash-safe sending; Payments shows the raw calls
    • MIT License
    JsonNumber
    PqcSigningError
    QbitRpcClient
    QbitRpcError
    RpcAbortedError
    RpcCapabilityError
    RpcChainGuardError
    RpcError
    RpcResponseError
    RpcResponseTooLargeError
    RpcTimeoutError
    RpcTransportError
    RpcUnknownOutcomeError
    AddressInfo
    AuxBlock
    Block
    BlockchainInfo
    BlockHeader
    BlockRef
    BlockTemplate
    BlockTemplateTransaction
    BlockTransaction
    BlockWithTransactions
    BumpedPsbt
    CallOptions
    ChainMismatch
    ChainTip
    ConfirmationTarget
    DataPqcHashProof
    DataPqcHashSignature
    DataPqcHashVerification
    DecodedTransaction
    DescriptorImport
    DescriptorInfo
    ExtraMethodPolicy
    FinalizedPsbt
    FundedPsbt
    FutureBlockTimeRule
    LastProcessedBlock
    ListSinceBlockOptions
    ListTransactionsOptions
    ListUnspentOptions
    LoadedWallet
    MempoolAcceptance
    MempoolEntry
    MempoolInfo
    MempoolSnapshot
    MiningInfo
    NetworkInfo
    NodeVersion
    Outpoint
    P2mrValidationWeightRule
    PackageSubmission
    PackageTransactionResult
    PqcKeyState
    PqcSigningKey
    PqcSigningPlan
    PqcUsage
    ProcessedPsbt
    PsbtBumpFeeOptions
    QbitRpcClientOptions
    RescanResult
    RpcConnectTarget
    RpcRequest
    RpcTlsOptions
    ScriptPubKey
    SinceBlockHistory
    SmartFeeEstimate
    TransactionOutput
    TxOut
    TxSpendingPrevout
    UnloadedWallet
    UnspentOutput
    WalletBalances
    WalletCreateFundedPsbtArgs
    WalletDirEntry
    WalletInfo
    WalletTransaction
    AddressType
    AddressValidation
    BatchItem
    BatchResults
    BlockSubmissionReason
    BlockSubmissionResult
    Capability
    ChainCheck
    ChainStatus
    ChainTipStatus
    ClientSatisfies
    DescriptorImportResult
    DescriptorRange
    FeeEstimateMode
    FundedPsbtOutput
    PqcLimitState
    PqcSigningRefusal
    QbitChain
    RpcAuth
    RpcCapabilityRefusal
    RpcChainGuardReason
    RpcConnect
    SecurityLevel
    SighashType
    TransactionInput
    UndeclaredKeys
    WalletHistoryEntry
    WalletTxCategory
    BITS_PER_QBT
    MAX_MONEY_BITS
    requests
    formatQbt
    parseQbt