DappClient

class DappClient(transport: DappTransport)

The dApp side of CIP-0103: typed calls onto a DappTransport.

val client = DappClient(transport)
if (client.connect().isConnected) {
val account = client.getPrimaryAccount()
val tx = client.prepareExecuteAndWait(PrepareSubmission(commands = commands))
println(tx.updateId)
}

Every method throws DappException when the wallet returns a JSON-RPC error, so 4001 (the user declined) arrives as an exception with DappException.isUserRejection set rather than as a null that is easy to mistake for "nothing happened".

This class holds no session state. Whether a connection exists is the wallet's answer to give, and caching it here would only let the two disagree — call isConnected or status to ask.

Constructors

Link copied to clipboard
constructor(transport: DappTransport)

Properties

Link copied to clipboard
val events: Flow<DappEvent>

Events pushed by the wallet, for transports that support them.

Functions

Link copied to clipboard
suspend fun connect(): ConnectResult

Requests a connection. The wallet decides, typically by asking the user.

Link copied to clipboard
suspend fun disconnect()

Ends the session. Idempotent by convention; wallets should not error on a repeat.

Link copied to clipboard

The network the wallet is currently on, as a CAIP-2 id plus optional endpoints.

Link copied to clipboard

The account the wallet treats as primary, among those granted.

Link copied to clipboard
suspend fun isConnected(): ConnectResult

Whether a connection exists, without prompting the user.

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

Calls the JSON Ledger API through the wallet, which supplies the credentials. The wallet applies its own policy — expect 4100 for resources outside it rather than assuming full ledger access.

Link copied to clipboard
suspend fun listAccounts(): List<DappWallet>

Accounts the user has granted this dApp. Not necessarily every account the wallet holds.

Link copied to clipboard
suspend fun prepareExecute(request: PrepareSubmission)

Submits request and returns as soon as the wallet accepts it.

Link copied to clipboard

Submits request and suspends until the transaction is executed.

Link copied to clipboard
suspend fun request(method: String, params: JsonElement? = null): JsonRpcResponse

Convenience for callers that want the raw frame — mainly tests and diagnostics.

Link copied to clipboard
suspend fun signMessage(message: String): SignMessageResult

Asks the wallet to sign an arbitrary message. Subject to user approval.

Link copied to clipboard
suspend fun status(): DappStatus

Provider identity, connection state, and — if connected — network and session.