Skip to main content

Overview

Smart Account Kit uses typed error classes that extend SmartAccountError. Catch them specifically to give users clear, actionable feedback.

Error Classes

import {
  SmartAccountError,
  WalletNotConnectedError,
  CredentialNotFoundError,
  SignerNotFoundError,
  SimulationError,
  SubmissionError,
  ValidationError,
  WebAuthnError,
  SessionError,
} from 'smart-account-kit';
ClassWhen thrown
WalletNotConnectedErrorA method requiring a connected wallet is called before connecting
CredentialNotFoundErrorThe requested credential ID is not in storage
SignerNotFoundErrorThe signer cannot be found on-chain
SimulationErrorSoroban simulation rejected the transaction
SubmissionErrorTransaction submission to the network failed
ValidationErrorInput validation failed
WebAuthnErrorWebAuthn browser API failed or user cancelled
SessionErrorSession restore or save failed

Usage

Catching specific errors

import {
  WalletNotConnectedError,
  SimulationError,
  WebAuthnError,
  SubmissionError,
} from 'smart-account-kit';

try {
  await kit.transfer(tokenContract, recipient, amount);
} catch (error) {
  if (error instanceof WalletNotConnectedError) {
    showConnectPrompt();
  } else if (error instanceof WebAuthnError) {
    // User cancelled the passkey prompt or the device rejected it
    showToast('Authentication cancelled or failed', 'warning');
  } else if (error instanceof SimulationError) {
    showToast('Transaction simulation failed: ' + error.message, 'error');
  } else if (error instanceof SubmissionError) {
    showToast('Transaction failed to submit', 'error');
  } else {
    throw error; // Re-throw unknown errors
  }
}

Using error codes

Each error class carries an errorCode property:
import { SmartAccountError, SmartAccountErrorCode } from 'smart-account-kit';

try {
  await kit.signAndSubmit(tx);
} catch (error) {
  if (error instanceof SmartAccountError) {
    switch (error.errorCode) {
      case SmartAccountErrorCode.WALLET_NOT_CONNECTED:
        // ...
        break;
      case SmartAccountErrorCode.SIMULATION_FAILED:
        // ...
        break;
      default:
        console.error('Unhandled SDK error:', error.errorCode, error.message);
    }
  }
}

wrapError utility

Wrap unknown caught values into SmartAccountError:
import { wrapError } from 'smart-account-kit';

try {
  await someOperation();
} catch (err) {
  const wrapped = wrapError(err);
  console.error(wrapped.errorCode, wrapped.message);
}

WebAuthn Cancellation

WebAuthnError is thrown when the user dismisses the passkey prompt or the browser rejects the WebAuthn ceremony. Always handle it gracefully - it’s expected user behaviour, not a bug:
try {
  await kit.connectWallet({ prompt: true });
} catch (error) {
  if (error instanceof WebAuthnError) {
    // User cancelled - stay on the connect screen
    return;
  }
  throw error;
}