Skip to content

Reference

waitForCompletion

Block until the completions WebSocket delivers the completion for a submission id, then return the ledger update id.

waitForCompletion opens a short-lived subscribeToCompletions subscription, filters frames until one matches your submissionId, then returns the updateId. It lives in completion-stream.ts and is re-exported from @fairmint/canton-node-sdk (same package as LedgerJsonApiClient).

Use it after asyncSubmit / interactive flows where you already have a submissionId and want to avoid polling HTTP completions.

Setup

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

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

Signature: waitForCompletion(ledgerClient: LedgerJsonApiClient, params: WaitForCompletionParams): Promise<string>

Minimal example

const submissionId = submitResponse.submissionId;

const updateId = await waitForCompletion(canton.ledger, {
  submissionId,
  partyId: canton.getPartyId(),
  userId: canton.getUserId()!,
  beginExclusive: checkpointOffset,
});

Pick beginExclusive from the same offset bookkeeping you use when subscribing (exclusive lower bound; typically before or at the submit offset per your pipeline).

Parameters — WaitForCompletionParams

  • submissionId (required, string) — Matches the submission returned by your async or interactive submit path.
  • partyId (required, string) — Party whose completions stream should include this submission (subscribeToCompletions parties filter).
  • userId (required, string) — Ledger user id aligned with the authenticated completions stream user.
  • beginExclusive (required, number) — Exclusive lower bound for the completions stream cursor.
  • timeoutMs (optional, number) — Max wait in milliseconds before rejecting (default 10 minutes).

Returns

Promise<string> — The ledger updateId string for the completed submission.

Errors

The promise rejects when:

  • The completion reports a non-zero status code (message from statusMessage when present).
  • The matching completion omits updateId.
  • The underlying subscription errors, closes before a matching completion, or timeoutMs elapses (Error: Timeout waiting for completion of submission …).

Auth and party

Uses the same OAuth path as LedgerJsonApiClient; userId / partyId must be consistent with subscribeToCompletions (which requires a resolvable user id—configure client user id or pass userId in the underlying subscribe).

See also

Source

src/clients/ledger-json-api/completion-stream.ts