JsonLedgerApiClient

class JsonLedgerApiClient(baseUrl: String, accessTokenProvider: suspend () -> String? = null, httpClient: OkHttpClient = OkHttpClient())

A minimal client for Canton's JSON Ledger API, used by the dApp provider for the two things that must go over JSON rather than gRPC: interactive-submission/prepare (see JsonPrepareExecutePipeline) and the ledgerApi proxy method.

Why JSON at all, in an SDK whose whole point is the gRPC Ledger API: a dApp authors its commands as JSON Ledger API shapes, and the participant must see them exactly as authored. Re-encoding them into proto would add a drift surface for every Daml value shape — precisely the risk the hash verification exists to catch. So the commands travel as the dApp wrote them, and only the prepared result crosses back into proto (which it can, because it crosses as bytes — see JsonPrepareExecutePipeline).

Field requirements are stricter than the published schema

Canton 3.5.12 serves its own OpenAPI at /docs/openapi, and that document under-reports required fields. Verified live: prepare documents commandId, commands and actAs as required, then rejects a request carrying exactly those three because synchronizerId and packageIdSelectionPreference are missing too. Do not generate a client from that document and expect it to work; send every field, empty collections included, as JsonPrepareExecutePipeline does.

Constructors

Link copied to clipboard
constructor(baseUrl: String, accessTokenProvider: suspend () -> String? = null, httpClient: OkHttpClient = OkHttpClient())

Functions

Link copied to clipboard
suspend fun call(request: LedgerApiRequest): JsonElement

Performs a dApp's ledgerApi request with the wallet's credentials.

Link copied to clipboard
suspend fun post(path: String, body: JsonObject): JsonElement

POSTs body to path and returns the decoded response.