Skip to content

Reference

BaseClient

Abstract base for Ledger, Validator, and Scan clients — authenticate, token lifecycle, HTTP helpers, party and user identity accessors.

BaseClient is the abstract superclass shared by the generated API clients. It binds an ApiType (LEDGER_JSON_API, VALIDATOR_API, or SCAN_API) to a CantonRuntime, resolves ApiConfig once in the constructor, and wires HttpClient with a token supplier that calls runtime.getAuthenticationManager(authUrl, apiConfig.auth).authenticate().

Use its public methods when you need explicit token control (authenticate, clearToken) or identity accessors (getPartyId, setPartyId, buildPartyList) inside helpers or tests.

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

Concrete subclasses (LedgerJsonApiClient, …) are what you hold in application code.

Example — explicit authenticate and GET

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

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

const ledger = canton.ledger;

const bearer = await ledger.authenticate();
console.log('token acquired', bearer.length > 0);

const base = ledger.getApiUrl();
const response = await ledger.makeGetRequest<{ version: string }>(`${base}/v2/version`, {
  includeBearerToken: true,
});
console.log(response.version);

Authentication and token lifecycle

  • authenticate(): Promise<string> — Retrieves bearer token from this client’s AuthenticationManager (same cache as other clients sharing identical (authUrl, AuthConfig) keys).
  • clearToken() — Clears cached token for this API’s auth tuple; next HTTP call or authenticate() refreshes.
  • getTokenExpiryTime() / getTokenIssuedAt() / getTokenLifetimeMs() — Metadata from the underlying manager for proactive refresh scheduling.

HTTP helpers

All delegate to HttpClient with the configured logger:

  • makeGetRequest<T>(url, config?)
  • makePostRequest<T>(url, data, config?)
  • makePatchRequest<T>(url, data, config?)
  • makeDeleteRequest<T>(url, config?)

RequestConfig supports contentType and includeBearerToken flags.

Party and user identity

Resolution order for party:

  1. ApiConfig.partyId on this API’s resolved config.
  2. Top-level clientConfig.partyId (updated by setPartyId / constructor merge).

getPartyId() throws ConfigurationError if neither is set.

  • setPartyId(partyId) — Mutates clientConfig.partyId only (does not rewrite env); pair with Canton.setPartyId when both ledger and validator must move together.
  • getUserId() — Prefers per-API userId, then clientConfig.userId.
  • getManagedParties() — Reads clientConfig.managedParties (often populated from env merge).
  • buildPartyList(additionalParties?) — Returns deduped array of additional parties, managed parties, and acting party (always included).

Other accessors

  • getApiUrl(), getAuthUrl(), getNetwork(), getProvider(), getApiType(), getProviderName(), getRuntime(), getLogger().

Errors and pitfalls

  • Missing API block: Constructor throws ConfigurationError if createClientConfig cannot supply apis[apiType].
  • Party not yet known: Local scripts that discover the party after startup must call setPartyId before commands that infer actAs.

See also

Source

src/core/BaseClient.ts on GitHub.