Skip to content

Reference

getEstimatedTrafficCost

Shape Ledger prepare responses into byte totals, overhead-adjusted totals, and dollar estimates using DEFAULT_PRICE_PER_MB_CENTS.

getEstimatedTrafficCost inspects InteractiveSubmissionPrepareResponse.costEstimation. When absent it returns undefined. Otherwise it aggregates confirmationRequestTrafficCostEstimation, confirmationResponseTrafficCostEstimation, adds UPDATE_CONFIRMATION_OVERHEAD_BYTES, and derives costInCents / costInDollars via calculateTrafficCostInCents / calculateTrafficCostInDollars.

Setup

import { getEstimatedTrafficCost } from '@fairmint/canton-node-sdk';

Minimal example

const prepared = await ledgerClient.interactiveSubmissionPrepare({
  commands: COMMAND_ARRAY_PLACEHOLDER,
  commandId: 'COMMAND_ID',
  userId: 'USER_ID',
  actAs: ['PARTY_ID'],
  readAs: [],
  synchronizerId: 'SYNCHRONIZER_ID',
  verboseHashing: false,
  packageIdSelectionPreference: [],
});

const estimate = getEstimatedTrafficCost(prepared);
console.log(estimate?.costInDollars);

Parameters

  • preparedTransaction — Raw InteractiveSubmissionPrepareResponse instance.

Returns

TrafficCostEstimate | undefined — Includes estimatedAt when server timestamps estimation.

Errors

Pure shaping logic — never throws unless malformed numeric coercion fails indirectly.

Auth and party

Not networked — consumes previously retrieved prepare payloads.

See also

Source

src/utils/traffic/get-estimated-traffic-cost.ts