connect Wallet
Connects to an existing smart account wallet.
Returns a ConnectWalletResult on successful connection, or null if no valid session exists and neither ConnectWalletOptions.prompt nor ConnectWalletOptions.fresh is set.
The non-null result is one of two sealed arms:
ConnectWalletResult.Connected: a single contract was resolved, the kit's connected state has been set, and a session has been saved.
ConnectWalletResult.Ambiguous: the indexer reported multiple contracts where the passkey is registered as a signer. The connected state has NOT been set; the caller must let the user pick a contract and re-call
connectWallet(ConnectWalletOptions(credentialId, contractId = chosen))to finalize.
Connection flow:
If credentialId/contractId provided: direct connect via connectWithCredentials.
If fresh = true: skip session, trigger WebAuthn authentication.
Otherwise, check storage for a valid (non-expired) session. If a valid session is found, verify the contract on-chain and reconnect. If verification returns NotFound (contract is not on-chain), clear the stale session and continue. Other exceptions during session verification propagate (the saved session is preserved so the user can retry once their network is healthy).
If no valid session and prompt = false: return null.
If no valid session and prompt = true: trigger WebAuthn authentication.
Resolve the contract via the cascade: storage → derivation → indexer. Storage with FAILED deployment status throws with a recovery hint. Derivation under the configured deployer is checked on-chain; if the address has no contract, falls through to the indexer. Indexer returns 0 / 1 / N>1 contracts mapping to NotFound / Connected / Ambiguous respectively.
On Connected: save session, set kit connected state, return. On Ambiguous: return early without saving a session.
Connection Options
Silent Session Check (default)
val result = walletOps.connectWallet()
when (result) {
null -> println("No active session - show login UI")
is ConnectWalletResult.Connected -> println("Connected: ${result.contractId}")
is ConnectWalletResult.Ambiguous -> { /* unreachable for the silent path */}
}Session Check with WebAuthn Fallback
val result = walletOps.connectWallet(
ConnectWalletOptions(prompt = true)
)
when (result) {
null -> { /* unreachable when prompt = true */}
is ConnectWalletResult.Connected -> println("Connected: ${result.contractId}")
is ConnectWalletResult.Ambiguous -> showPicker(result.candidates)
}Direct Connection
val result = walletOps.connectWallet(
ConnectWalletOptions(
credentialId = "abc123...",
contractId = "CABC..."
)
)
// Explicit contractId bypasses the cascade. The non-null result is
// always Connected; Ambiguous is by-construction unreachable.Force Fresh Authentication
val result = walletOps.connectWallet(
ConnectWalletOptions(fresh = true)
)
// Always prompts WebAuthn, ignoring any saved session.IMPORTANT: Requires a WebAuthnProvider to be configured in the kit config when WebAuthn authentication is needed (prompt = true or fresh = true).
Return
ConnectWalletResult on success, or null if no session and prompt is false.
Parameters
Connection options controlling the flow behavior.
See also
for detailed option descriptions and the decision matrix.
Throws
if WebAuthn authentication fails or no provider is configured.
if no contract can be resolved for the credential (e.g. a FAILED storage entry, no on-chain contract at the derived address, or the indexer reports zero contracts).
if options are invalid (e.g. contractId without credentialId), or if the configured deployer's public key is malformed.
if XDR encoding of the contract-id preimage fails (an internal SDK bug).
if a Soroban RPC call (e.g. the on-chain verifyContractExists check) fails for transport / server reasons. RPC errors propagate as their original type rather than being laundered to NotFound, so callers can distinguish "contract is not on-chain" from "lookup was inconclusive."
if the indexer call fails for transport / server reasons.