Skip to main content

Public API: C8WalletProvider

MethodParametersReturn Type
connect()NonePromise<void>
disconnect()NonePromise<void>
status()NonePromise<{ connected: boolean; walletVersion?: string }>
getInstruments()NonePromise<InstrumentListPayload>
getAccounts()instrumentId?: stringPromise<AccountListPayload>
send()input: SendInputPromise<SubmitTransferResultPayload>
signAndExecute()input: SignAndExecuteInputPromise<void>
checkTxStatusById()input: { txId: string }Promise<TransferStatusResponsePayload>
on()event: T, cb: Listener<C8EventByType<T>>() => boolean

Constructor

Creates a new wallet provider instance.
new C8WalletProvider(config)
dappUrl
string
URL of the dApp initiating the connection. Defaults to the current page URL.
dappName
string
required
Name of the dApp. Must match the name registered with the wallet.
network
string
Canton network to connect to. One of "devnet" or "mainnet".

connect

Opens the C8 Wallet popup and establishes the postMessage channel. The user sees a connection approval screen in the wallet.
connect(): Promise<void>
returns
Promise<void>
Resolves when the user approves the connection.
Must be called from a user gesture (e.g. button click) to avoid POPUP_BLOCKED errors.

disconnect

Closes the wallet popup and tears down the postMessage channel. Emits the disconnected event.
disconnect(): Promise<void>

status

Returns the current connection state.
status(): Promise<{ connected: boolean, walletVersion?: string }>
connected
boolean
Whether the wallet is currently connected.
walletVersion
string
Version of the connected wallet (only present when connected).

getInstruments

Returns the list of Canton instruments available in the connected wallet.
getInstruments(): Promise<InstrumentListPayload>

type InstrumentListPayload = {
  instruments: Array<{
    instrumentId: string
    name: string
    symbol: string
  }>
}

getAccounts

Returns accounts and their holdings. If instrumentId is provided, filters to accounts holding that instrument.
getAccounts(instrumentId?: string): Promise<AccountListPayload>

type AccountListPayload = {
  accounts: Array<{
    partyId: string
    holdings: Array<{
      instrumentId: string
      balance: number
      balanceUsd: number
    }>
  }>
}
instrumentId
string
Optional. Filters accounts to those holding this instrument.

send

Submits a transfer on the Canton ledger. Opens an approval screen in the wallet popup.
send(input): Promise<SubmitTransferResultPayload>
senderPartyId
string
required
Canton partyId of the sender.
instrumentId
string
required
Asset to transfer.
amount
number
required
Transfer amount.
receiverPartyId
string
required
Canton partyId of the recipient.
memo
string
Optional text memo attached to the transfer.
metadata
Record<string, string>
Optional arbitrary key-value metadata.
txId
string
Transaction ID assigned by the Canton ledger. Use it with checkTxStatusById.

signAndExecute

Signs and executes an arbitrary DAML command via the connected wallet. Use this for custom templates and choices beyond standard transfers. See Transfer types for the full example.
signAndExecute(input): Promise<void>
note
string
required
Human-readable note shown to the user in the wallet UI.
partyId
string
required
The party submitting the command.
commandId
string
required
Unique idempotency key for this submission (e.g. a UUID).
commandsJson
string
required
JSON-serialized array of DAML commands (CreateCommand, ExerciseCommand, etc.).
disclosedContracts
string
required
JSON-serialized array of contracts disclosed to the participant to authorize the command.

on

Subscribes to a wallet event. Returns an unsubscribe function. See Events for the full event reference.
on<T extends C8EventType>(event: T, cb: Listener<C8EventByType<T>>): () => boolean
event
string
required
Event type to subscribe to (e.g. "connected", "txChanged").
cb
Listener
required
Callback invoked with the typed event payload.
returns
() => boolean
Unsubscribe function. Call it to remove the listener.

checkTxStatusById

Polls the Canton ledger for the current status of a previously submitted transaction.
checkTxStatusById(input): Promise<TransferStatusResponsePayload>
txId
string
required
Transaction ID returned by send().
returns
Promise<TransferStatusResponsePayload>
Current ledger status for the given transaction.