Skip to content

Reference

estimateTrafficCost

Wrap interactiveSubmissionPrepare without executing on-chain work so traffic bytes and dollar estimates can be inspected ahead of submission.

estimateTrafficCost generates a commandId, forwards interactiveSubmissionPrepare with merged defaults (userId / actAs fall back to ledger client configuration), then delegates fee shaping to getEstimatedTrafficCost.

Requires userId (explicit or configured on LedgerJsonApiClient) and actAs parties.

Setup

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

const canton = new Canton({
  network: 'NETWORK_NAME',
  partyId: 'PARTY_ID',
});

Minimal example

const estimate = await estimateTrafficCost({
  ledgerClient: canton.ledger,
  commands: COMMAND_ARRAY_PLACEHOLDER,
  synchronizerId: 'SYNCHRONIZER_ID',
});

console.log(estimate?.totalCostWithOverhead, estimate?.costInDollars);

Parameters

EstimateTrafficCostOptions:

  • ledgerClient (required) — Supplies interactiveSubmissionPrepare.
  • commands (required) — Same CreateCommand / ExerciseCommand inputs as interactive submission.
  • synchronizerId (required) — Domain ID hosting the commands.
  • actAs, readAs, userId, disclosedContracts, packageIdSelectionPreference — Forwarded verbatim after defaults merge.

Returns

Promise<TrafficCostEstimate | undefined>undefined when costEstimation absent from prepare response.

Errors

Throws Error when userId or actAs cannot be resolved.

Auth and party

Uses authenticated ledger credentials suitable for interactiveSubmissionPrepare.

See also

Source

src/utils/traffic/estimate-traffic-cost.ts