@arkade-os/sdk Documentation - v0.4.21
    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.

      Active contracts are immediately subscribed.

      All contracts are polled to discover any existing virtual outputs (which may cause them to be watched even if inactive).

      Parameters

      Returns Promise<void>

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

      Returns Promise<void>

    • Contracts the watcher is actually tracking:

      • all active contracts, plus
      • inactive contracts that still hold known virtual outputs (the subscription keeps watching them so vtxo_spent events for those unspent outputs are still observed).

      This is the single source of truth for "contracts whose VTXO state we still care about" — callers and the subscription itself fan out over the same set so nothing is reconciled that isn't also watched.

      Returns Contract[]

    • Remove a contract from watching.

      Parameters

      • contractScript: string

      Returns Promise<void>