qbit-rpc
    Preparing search index...

    Class QbitRpcClient

    A JSON-RPC client for one qbit Core node (and optionally one wallet).

    Every method is checked against an allowlist and the client's capabilities before anything is sent, wallet-write, broadcast, mining and wallet-admin calls also need a confirmed chain, and every typed result is validated before it is returned. Amounts are bigint bits. See Errors for the failure model.

    Each typed method takes the arguments of the request builder of the same name in requests, then CallOptions (signal, timeoutMs) as a separate last argument: getTxOut(txid, vout, { includeMempool }, { timeoutMs }). A method's own options never hold call options.

    Index
    • get nodeVersion(): NodeVersion | undefined

      The qbit Core version the node reported (getnetworkinfo's version and subversion) to the newest chain check sent that read one; undefined before then. supported says whether this package supports it: qbit Core 1.0.x releases. See allowUnsupportedNodeVersion.

      Returns NodeVersion | undefined

    • Send several read or wallet-read requests, long polls apart, in one JSON-RPC batch, matched to their replies by id. Each entry succeeds or fails on its own, a throwing parse included; a transport failure, timeout or oversized reply rejects the whole batch.

      Type Parameters

      Parameters

      Returns Promise<BatchResults<T>>

    • Call any allowlisted method, or one in extraMethods, with positional parameters. The result is returned unvalidated, with every number as a JsonNumber. Pass amounts as strings from formatQbt(bits) (qbit Core accepts amount strings) and integers above 2^53 as bigint.

      Parameters

      • method: string
      • params: readonly unknown[] = []
      • OptionalcallOptions: CallOptions

      Returns Promise<unknown>

    • Count the PQC signatures signing psbt with this wallet would take from each of its keys, before signing: decodepsbt gives the address of the output each input spends, and getaddressinfo, for each address once in one batch, its keys' states and signatures left. Each input needs one signature from each key its address holds. Rejects with PqcSigningError when an input names no address, a PQC state comes without its keys, a key is exhausted or in a state this version does not know, or a key has fewer signatures left than it needs. Resolves with each key's count, the worst state, and a warning per critical key; an input whose address holds no PQC key of this wallet needs none. Needs wallet-read; nothing is signed. walletProcessPsbt runs it by default.

      Parameters

      Returns Promise<PqcSigningPlan>

    • Close pooled keep-alive connections. The client stays usable; later calls open new ones.

      Returns void

    • Send getblockchaininfo, getblockhash 0 and getnetworkinfo in one JSON-RPC batch, and compare the node's chain with expectedChain, its genesis block hash with expectedGenesisHash and, on signet, its signet_challenge with expectedSignetChallenge (a missing one differs), and read its version into nodeVersion. On a match of all three, on a supported version (or with allowUnsupportedNodeVersion), wallet-write, broadcast, mining and wallet-admin calls are allowed; once the confirmation goes stale they re-run this check before they are sent. On a mismatch, or an unsupported version, they stay refused and this throws RpcChainGuardError (mismatch or unsupported_version), as it does when any check finds one while this call runs (its cookie read, checks, waits and retries included), unless a confirmChain() begun after that mismatch cleared it first. It returns its own last check's getblockchaininfo answer, which another check may have overtaken: call getBlockchainInfo() for current block data. An unsupported version is reported even when the node's getblockchaininfo reply does not validate, as it may well be why. An answer that a connection error or an HTTP 401 elsewhere may postdate is checked again, after retryDelayMs, up to three checks per attempt; then this throws reason: 'stale' (retried like a read under readRetries) and changes nothing. This is a read and the check itself, so any other failure of it is thrown as it is (RpcTimeoutError, RpcTransportError and so on, about getblockchaininfo, getblockhash or getnetworkinfo, a version that does not parse included), never reason: 'check_failed'.

      Parameters

      Returns Promise<BlockchainInfo>

    • See requests.createWallet. Needs wallet-admin, as do the eight methods after it.

      Parameters

      • walletName: string
      • Optionaloptions: {
            avoidReuse?: boolean;
            blank?: boolean;
            disablePrivateKeys?: boolean;
            loadOnStartup?: boolean;
            passphrase?: string;
        }
      • OptionalcallOptions: CallOptions

      Returns Promise<LoadedWallet>

    • See requests.getBlockTemplate. With expectedChain: 'signet', the rules default to ['segwit', 'signet'], as qbit Core requires there.

      Parameters

      • Optionaloptions: { capabilities?: readonly string[]; rules?: readonly string[] }
      • OptionalcallOptions: CallOptions

      Returns Promise<BlockTemplate>

    • Lock wallet outputs against automatic coin selection, in memory or, with persistent, in the wallet. Resolves once every output is locked; see requests.lockUnspent.

      Parameters

      • outputs: readonly Outpoint[]
      • Optionaloptions: { persistent?: boolean }
      • OptionalcallOptions: CallOptions

      Returns Promise<void>

    • Parameters

      • hex: string
      • Optionaloptions: { maxBurnAmountBits?: bigint; maxFeeRateBitsPerKvB?: bigint }
      • OptionalcallOptions: CallOptions

      Returns Promise<string>

    • See requests.signDataPqcHash: each signature counts against the key's PQC signature budget.

      Parameters

      • address: string
      • messageHash: string
      • Optionaloptions: {
            controlBlock?: string;
            includePqcUsage?: boolean;
            leafScript?: string;
            pubkey?: string;
        }
      • OptionalcallOptions: CallOptions

      Returns Promise<DataPqcHashSignature>

    • Long-poll for a new tip. The deadline is the call's timeoutMs, which must be at least waitMs plus 10 s, else the longer of that and the client's timeoutMs. Without options.currentTip it is never retried: a retry would wait from the tip at that time, past a block found meanwhile. With it, a retry under readRetries asks for no more than the deadline has left. See requests.waitForNewBlock.

      Parameters

      • waitMs: number
      • Optionaloptions: { currentTip?: string }
      • OptionalcallOptions: CallOptions

      Returns Promise<BlockRef>

    • Lock the wallet. qbit Core answers only once a first unlock still running has ended, so the default deadline is QbitRpcClient.walletPassphrase's: the call's timeoutMs if it gives one, else the longer of 120 s and the client's timeoutMs. A deadline missed once the request was sent is an RpcUnknownOutcomeError; one missed before that is an RpcTimeoutError, or RpcChainGuardError check_failed with one as its cause.

      Parameters

      Returns Promise<void>

    • Unlock the wallet for timeoutSeconds, counted from when the unlock ends. The deadline is the call's timeoutMs if it gives one, else the longer of 120 s and the client's timeoutMs: qbit Core v1.0.0 runs a new encrypted wallet's deferred keypool top-up inside its first unlock, which took 25 to 49 s on regtest. A deadline missed once the request was sent is an RpcUnknownOutcomeError: the wallet may be unlocked, and getWalletInfo().unlockedUntil (0 when locked) tells. One missed before that (waiting for a request slot, reading the cookie, connecting, or in the chain re-check) is an RpcTimeoutError, or RpcChainGuardError check_failed with one as its cause, and nothing was sent. Every call on that wallet waits for a first unlock, and the others keep the client's deadline, so one sent meanwhile can need a longer timeoutMs. See Unlocking.

      Parameters

      • passphrase: string
      • timeoutSeconds: number
      • OptionalcallOptions: CallOptions

      Returns Promise<void>

    • See requests.walletProcessPsbt. When it signs (sign is not false), it first runs QbitRpcClient.checkPqcSigning on psbt and sends nothing to sign when that refuses: an exhausted PQC key signs nothing and raises no error, and one that runs out partway leaves the inputs after it unsigned. So it needs wallet-read too. The check's decodepsbt, getaddressinfo batch and the signing share one deadline, the call's, and its signal; a failure of the check is thrown as it is, with nothing signed. pqcCheck: false skips the check, which is unsafe: only for a caller that counts the budgets itself, or knows the wallet has no PQC key.

      Parameters

      • psbt: string
      • Optionaloptions: {
            bip32derivs?: boolean;
            finalize?: boolean;
            pqcCheck?: boolean;
            sighashType?: SighashType;
            sign?: boolean;
        }
      • OptionalcallOptions: CallOptions

      Returns Promise<ProcessedPsbt>