Skip to content

Reference

ledger.subscribeToUpdates

WebSocket /v2/updates — bounded replay or live ledger updates with party/template filters and TransactionShape.

Opens WebSocketClient on /v2/updates. SubscribeToUpdates.connect returns Promise<void>: resolves when the socket closes cleanly, rejects on Canton error frames or transport failures.

Bounded mode: both beginExclusive and endInclusive → replay stops at endInclusive. Unbounded: omit endInclusive ( beginExclusive defaults from getLedgerEnd when omitted).

Receiver: await canton.ledger.subscribeToUpdates(params)

Setup

import { Canton, TransactionShape } from '@fairmint/canton-node-sdk';

const canton = new Canton({
  network: 'devnet',
  provider: '5n',
  partyId: 'OWN_PARTY_ID',
});

Minimal example

await canton.ledger.subscribeToUpdates({
  beginExclusive: 0,
  parties: [canton.getPartyId()],
  transactionShape: TransactionShape.TRANSACTION_SHAPE_LEDGER_EFFECTS,
  onMessage: (msg) => {
    if ('update' in msg) console.log(msg.update);
  },
});

Parameters — SubscribeToUpdatesParams

Core (schema): optional parties, templateIds, includeCreatedEventBlob, beginExclusive, endInclusive, includeReassignments (default true), includeTopologyEvents (default false), transactionShape.

Callbacks (extended): optional onMessage (UpdatesWsMessage union { update }, JsCantonError, WsCantonError), onTokenExpiring, onTokenRefreshNeeded ( WebSocketOptions — closes socket after refresh hint).

Returns

Promise<void>. No subscription handle on LedgerJsonApiClient (promise lifecycle only).

Errors

Canton error payloads routed through onMessage also reject the promise (ApiError wrapping diagnostics).

Auth and party

Defaults parties via buildPartyList() when omitted—needs read-as rights matching parties.

See also

Source

operations/v2/updates/subscribe-to-updates.ts