Skip to content

Reference

CantonRuntime

Shared Canton runtime — logger, merged ClientConfig, authentication-manager registry, fork overrides, and createClientConfig per ApiType.

CantonRuntime holds the mutable effective ClientConfig (including merged env defaults), the shared Map of AuthenticationManager instances, and the resolved logger. Every LedgerJsonApiClient, ValidatorApiClient, and ScanApiClient receives the same runtime instance so tokens and HTTP behavior stay aligned.

You access it as canton.runtime from Canton, or via BaseClient.getRuntime() when writing extensions.

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

Example — fork with debug logger

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

const canton = new Canton({
  network: 'localnet',
});

const debugRuntime = canton.runtime.fork({
  debug: true,
  logger: new ConsoleLogger({ logLevel: 'debug' }),
});

const altLedger = new LedgerJsonApiClient(debugRuntime);
await altLedger.getVersion();

Prefer the original canton.ledger unless you intentionally split configuration for tests or parallel identities.

Methods and properties

  • constructor(config, authManagers?) — Copies config, fills default logger via createLogger (FileLogger, or CompositeLogger + ConsoleLogger when debug), optionally reuses an existing auth-manager map (used by fork).
  • fork(overrides) — Returns a new CantonRuntime with shallow-merged ClientConfig, merged apis maps, shared same authManagers map — sessions stay unified across forks.
  • createClientConfig(apiType) — Returns a ClientConfig view containing only the resolved apis[apiType] entry plus top-level fields. On first access for an API, calls EnvLoader.getConfig if that API was not explicitly configured, then merges provider/party/user/managedParties/authUrl onto baseConfig as side effects.
  • getAuthenticationManager(authUrl, authConfig) — Returns cached AuthenticationManager or constructs one.
  • getNetwork() / getProvider() / getLogger() — Read merged base configuration.

Errors and pitfalls

  • Side effects on resolve: First resolution of an API mutates baseConfig (fills missing provider, auth URL, party id, user id, managed parties from env). Order of client construction can therefore matter for what gets merged.
  • fork logger: If overrides.logger is omitted, the fork keeps the parent logger explicitly.

See also

Source

src/core/runtime/CantonRuntime.ts on GitHub.