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’sAuthenticationManager(same cache as other clients sharing identical(authUrl, AuthConfig)keys).clearToken()— Clears cached token for this API’s auth tuple; next HTTP call orauthenticate()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:
ApiConfig.partyIdon this API’s resolved config.- Top-level
clientConfig.partyId(updated bysetPartyId/ constructor merge).
getPartyId() throws ConfigurationError if neither is set.
setPartyId(partyId)— MutatesclientConfig.partyIdonly (does not rewrite env); pair withCanton.setPartyIdwhen both ledger and validator must move together.getUserId()— Prefers per-APIuserId, thenclientConfig.userId.getManagedParties()— ReadsclientConfig.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
ConfigurationErrorifcreateClientConfigcannot supplyapis[apiType]. - Party not yet known: Local scripts that discover the party after startup must call
setPartyIdbefore commands that inferactAs.
See also
- AuthenticationManager — token mechanics behind
authenticate. - Canton —
setPartyIdacross ledger and validator. submitAndWait— defaultactAsuses party identity.
Source
src/core/BaseClient.ts on GitHub.