createWallet

suspend fun createWallet(userName: String = "Smart Account User", autoSubmit: Boolean = false, autoFund: Boolean = false, nativeTokenContract: String? = null, forceMethod: SubmissionMethod? = null): CreateWalletResult

Creates a new smart account wallet with WebAuthn passkey authentication.

Creates a new wallet by generating a WebAuthn credential, deriving the contract address, and optionally deploying the smart account contract to the network.

Flow:

  1. Validate WebAuthn provider and autoFund requirements

  2. Call WebAuthn registration (user authenticates with biometric/security key)

  3. Extract and normalize secp256r1 public key from attestation

  4. Derive deterministic contract address from credential ID

  5. Save credential as pending in storage

  6. Set connected state and save session (before deployment)

  7. Build and sign the deploy transaction (always, regardless of autoSubmit)

  8. If autoSubmit: submit the transaction, fund wallet if autoFund, delete credential

  9. Return result

Auto-Fund Feature

When autoFund = true, the wallet is automatically funded after deployment using Friendbot (testnet only). This is useful for onboarding flows where users need immediate access to a funded wallet.

Requirements for autoFund:

  • autoSubmit must be true (wallet must be deployed first)

  • nativeTokenContract must be provided (the native token contract address)

  • Must be on testnet (Friendbot is testnet-only)

  • Relayer may be used for fee sponsoring if configured

IMPORTANT: Requires a WebAuthnProvider to be configured in the kit config. Throws WEBAUTHN_NOT_SUPPORTED if no provider is configured.

Return

CreateWalletResult containing credential ID, contract address, signed transaction XDR, and optional transaction hash

Parameters

userName

Display name for the user (default: "Smart Account User")

autoSubmit

Whether to automatically submit the deploy transaction (default: false)

autoFund

Whether to automatically fund the wallet after deployment (default: false)

nativeTokenContract

Contract address for the native token (required if autoFund is true)

forceMethod

Optional override to force relayer or RPC submission (default: auto-detect)

See also

for manual funding after deployment

for retrying a failed or deferred deployment

Throws

if WebAuthn registration fails or no provider configured

if public key extraction fails or nativeTokenContract is missing when autoFund is true

if deployment or funding fails

if credential storage fails

if storage write fails

Example:

// Create wallet without deploying — signedTransactionXdr always present for external submission
val wallet = walletOps.createWallet(userName = "Alice", autoSubmit = false)
println("Wallet address: ${wallet.contractId}")
println("Signed XDR: ${wallet.signedTransactionXdr}")

// Create and deploy immediately
val deployedWallet = walletOps.createWallet(userName = "Bob", autoSubmit = true)
println("Deployed at: ${deployedWallet.transactionHash ?: "unknown"}")

// Create, deploy, and fund with native token (testnet)
val fundedWallet = walletOps.createWallet(
userName = "Charlie",
autoSubmit = true,
autoFund = true,
nativeTokenContract = "CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC"
)
println("Funded wallet at: ${fundedWallet.contractId}")