CantonClient

class CantonClient(channel: ManagedChannel, callCredentials: CallCredentials? = null, retryPolicy: RetryPolicy = RetryPolicy.DEFAULT, accessTokenProvider: suspend () -> String? = null) : Closeable

A client for the Canton Ledger API.

val client = CantonClient(
CantonClientConfiguration(host = "validator.example.com")
)
val version = client.ledgerApiVersion()

The channel-based constructor is useful for tests (in-process transport) and for callers who need full control over the ManagedChannel.

Constructors

Link copied to clipboard
constructor(channel: ManagedChannel, callCredentials: CallCredentials? = null, retryPolicy: RetryPolicy = RetryPolicy.DEFAULT, accessTokenProvider: suspend () -> String? = null)
constructor(configuration: CantonClientConfiguration)

Opens an OkHttp-backed gRPC channel to CantonClientConfiguration.host — TLS with the configured TlsTrust unless useTls is off — and takes the retry policy and access-token provider from the same configuration. The client owns the channel it built: close shuts it down.

Functions

Link copied to clipboard
suspend fun activeContracts(parties: List<String>, activeAtOffset: Long, verbose: Boolean = true): List<ActiveContract>

The active contract set visible to parties at activeAtOffset (all templates). Retryable failures restart the snapshot from scratch, so the result is never partial.

Link copied to clipboard
suspend fun activeContractsSnapshot(parties: List<String>, verbose: Boolean = true): ActiveContractsSnapshot

The active contract set at the current ledger end — the starting point for a full state sync. Apply ActiveContractsSnapshot.contracts, then consume updates from ActiveContractsSnapshot.offset:

Link copied to clipboard
open override fun close()
Link copied to clipboard
suspend fun ledgerApiVersion(): String

Fetches the Ledger API version from the participant.

Link copied to clipboard
suspend fun ledgerEnd(): Long

The participant's current ledger end offset — the natural UpdateSubscription.beginExclusive for a fresh subscription.

Link copied to clipboard
suspend fun submitAndWait(submission: CommandSubmission): String

Submits submission and waits for it to be committed, returning the update id. Retryable failures are retried with the same command id, so the participant deduplicates re-executions.

Link copied to clipboard
suspend fun submitAndWaitForTransaction(submission: CommandSubmission): TransactionOuterClass.Transaction

Submits submission, waits for it to be committed, and returns the resulting transaction (flat/ACS-delta shape, filtered to the submitting parties). Retries reuse the same command id.

Link copied to clipboard
fun updates(subscription: UpdateSubscription): Flow<LedgerUpdate>

Streams ledger updates for subscription, transparently reconnecting on retryable failures and resuming from the offset of the last received update — consumers see one uninterrupted, gap-free stream. The retry budget resets only once a connection has proven healthy: it delivered at least one update and stayed alive for RetryPolicy.streamHealthyWindow. Shorter-lived connections keep escalating the backoff until RetryPolicy.maxAttempts is exhausted.