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

    Class ContractWatcher

    Watches multiple contracts for virtual output state changes with resilient connection handling.

    Features:

    • Automatic reconnection with exponential backoff
    • Failsafe polling to catch missed events
    • Polls immediately after (re)connection to sync state
    • Graceful handling of subscription failures
    const watcher = new ContractWatcher({
    indexerProvider: wallet.indexerProvider,
    });

    // Add the wallet's default contract
    await watcher.addContract(defaultContract);

    // Add additional contracts (swaps, etc.)
    await watcher.addContract(swapContract);

    // Start watching for events
    const stop = await watcher.startWatching((event) => {
    console.log(`${event.type} on contract ${event.contractScript}`);
    });

    // Later: stop watching
    stop();
    Index

    Constructors

    Methods

    • Add a contract to be watched.

      Once watching, every contract is subscribed and polled whatever its state.

      Parameters

      Returns Promise<void>

      getWatchedContracts

    • Force a poll of all watched contracts. Useful for manual refresh or after app resume.

      Returns Promise<void>

    • Every registered contract, retired (inactive) ones included.

      Feeds both the subscription and the indexer sweep scope, so narrowing it drops a contract from every background channel at once. Nothing may be narrowed out: an Ark receive address can be paid again after the wallet has rotated past it, and a payment that lands outside every background channel is invisible until some foreground read happens to sweep it. Retirement therefore governs receive-address selection, not coverage.

      Returns Contract[]

    • Remove a contract from watching.

      Parameters

      • contractScript: string

      Returns Promise<void>

    • Run fn with subscription updates coalesced into a single subscribeForScripts on the way out.

      addContract re-subscribes eagerly (the watcher may already be running), and every subscribe posts the whole accumulated script list — so a restore scan that discovers N contracts sends N growing POSTs, quadratic in script-slots. Inside this scope those updates are only marked dirty, flushed once on the way out (success and error path alike).

      A contract added inside the scope is therefore not streaming until the flush. Nothing in the watcher closes that window — the failsafe poll replays repository state and cannot see VTXOs no one has fetched yet. The one caller, scanContracts, is covered because Wallet.restore follows it with a bulk refreshVtxos. A new caller must provide its own equivalent catch-up, or keep the scope short enough not to need one.

      Type Parameters

      • T

      Parameters

      • fn: () => Promise<T>

      Returns Promise<T>