@arkade-os/sdk Documentation - v0.4.36
    Preparing search index...

    Class WsElectrumChainSource

    WebSocket-based Electrum chain source using ws-electrumx-client. Provides low-level methods for the Electrum protocol.

    import { ElectrumWS } from "ws-electrumx-client";
    import { WsElectrumChainSource } from "./providers/electrum";
    import { networks } from "./networks";

    const ws = new ElectrumWS("wss://electrum.blockstream.info:50004");
    const chain = new WsElectrumChainSource(ws, networks.bitcoin);

    const history = await chain.fetchHistories([script]);
    await chain.close();
    Index

    Constructors

    Methods

    • Get the address string for a script output, if decodable.

      Parameters

      • scriptHex: string

      Returns string | undefined

    • Submit a package of raw transactions atomically via Fulcrum's blockchain.transaction.broadcast_package method, the on-the-wire equivalent of bitcoind's submitpackage RPC.

      Required for TRUC (BIP 431) 1P1C relay where the parent has zero (or below-minfee) fee and depends on the child to pay for both via CPFP — sequential broadcast cannot work in that case because the parent would be rejected from the mempool on its own.

      Parameters

      • txHexes: string[]

        Topologically sorted raw transactions; child must be the last element. Currently must be a 1P1C pair (length 2). Parents may not depend on each other.

      Returns Promise<string>

      The child transaction id (the last entry in the array), computed locally — broadcast_package itself returns {success, errors} rather than a txid.

      If the server does not implement broadcast_package (e.g. ElectrumX, or older Fulcrum, or Fulcrum backed by bitcoind < v28.0.0). Callers must surface this clearly to users — this method does NOT silently fall back to sequential broadcasts because doing so would let TRUC packages fail in subtle ways.

      If the server returns success=false, surfacing the underlying mempool rejection in the error message.

    • Parameters

      • txHex: string

      Returns Promise<string>

    • Parameters

      • targetNumberBlocks: number

      Returns Promise<number>

    • Parameters

      • txids: string[]

      Returns Promise<{ hex: string; txID: string }[]>

    • Look up the block height of a confirmed transaction without relying on the verbose-tx endpoint. blockchain.transaction.get_merkle is part of the standard SPV protocol and is supported by both Fulcrum and electrs (whereas blockchain.transaction.get with verbose=true is Fulcrum-only). Returns null when the tx is in the mempool — electrs in that case rejects with a "not yet in a block" error.

      Parameters

      • txid: string

      Returns Promise<{ blockHeight: number } | null>

    • Parameters

      • txid: string

      Returns Promise<VerboseTransaction>

    • Parameters

      • txids: string[]

      Returns Promise<VerboseTransaction[]>

    • Send N requests in parallel and aggregate the results, replacement for ws.batchRequest. The library's batchRequest is implemented as Promise.all over individual request promises — when one element rejects, the others remain pending. When their (often error) responses arrive later, the library rejects them too, and nobody is awaiting them: the rejections become unhandled and crash the test runner / pollute production logs.

      safeBatchRequest issues each request through ws.request (so each has its own request-promise lifecycle), waits for all of them via Promise.allSettled (every promise gets an explicit handler), and then surfaces the first error if any failed. Same wall-clock cost as the library's batch (parallel send), no orphan rejections.

      Use this in place of ws.batchRequest for any call where one or more elements may legitimately error (e.g. electrs index lag surfacing as missingheight for a subset of heights/txids).

      Type Parameters

      • T

      Parameters

      • requests: { method: string; params: unknown[] }[]

      Returns Promise<T[]>

    • Returns the current chain tip and keeps it fresh via a single server-side subscription. Subsequent calls return the cached tip (updated by background notifications) without round-tripping to the server. Previously each call issued blockchain.headers.subscribe as a regular request, leaving a stale subscription on the server every time — under polling that adds up. ws-electrumx-client deduplicates subscribe() by method+params, so registering once is enough.

      Returns Promise<HeaderSubscribeResult>

    • Parameters

      • script: Uint8Array
      • callback: (scripthash: string, status: string | null) => void

      Returns Promise<void>

    • Parameters

      • script: Uint8Array

      Returns Promise<void>

    • Parameters

      • addr: string

      Returns Promise<void>