Skip to content

Errors

Wallet failures throw ConnectSdkError with a stable code. Branch on code, not on message.

ts
import {
  ConnectSdkError,
  ConnectSdkErrorCode,
} from '@swapped/connect-sdk';

try {
  await client.wallets.connect({ provider });
} catch (error) {
  if (!(error instanceof ConnectSdkError)) {
    throw error;
  }

  switch (error.code) {
    case ConnectSdkErrorCode.WALLET_CONNECT_REJECTED:
    case ConnectSdkErrorCode.WALLET_PAIRING_CANCELLED:
      break;
    case ConnectSdkErrorCode.WALLET_PAIRING_IN_PROGRESS:
      await client.wallets.cancelPairing();
      break;
    case ConnectSdkErrorCode.WALLET_POPUP_BLOCKED:
      break;
    default:
      break;
  }
}

WALLET_CONNECT_REJECTED and WALLET_TRANSACTION_REJECTED are user cancels (wallet declined connect or the send). WALLET_PAIRING_CANCELLED is an SDK/host abort of an in-flight WalletConnect pairing (cancelPairing or connect({ force: true }) superseding it).

Connect / disconnect

CodeWhen
WALLET_NOT_SUPPORTEDPayment method provider has no SDK wallet config
WALLET_NOT_INSTALLEDInjected connect and the extension is not present
WALLET_ALREADY_CONNECTEDInjected slot for that provider is already connected
WALLET_CONNECT_REJECTEDUser rejected the connect request in the wallet
WALLET_NAMESPACE_UNSUPPORTEDRequested namespace is not available
WALLET_CHAIN_UNSUPPORTEDRequested chain is not available
WALLET_PAIRING_IN_PROGRESSA WalletConnect pairing is already in flight
WALLET_PAIRING_CANCELLEDIn-flight pairing was cancelled
WALLET_POPUP_BLOCKEDBrowser blocked the connect popup
WALLET_POPUP_CLOSEDPopup closed before connect finished
WALLET_POPUP_IN_PROGRESSAnother popup connect is already open
WALLET_POPUP_NO_OPENERPopup could not reach the opener
WALLET_GATEWAY_NOT_READYWallet host is not ready
WALLET_SESSION_EXPIREDWalletConnect session expired

Transfer

CodeWhen
WALLET_NOT_CONNECTEDNo connection for that walletId (or no address for the network)
WALLET_TRANSACTION_REJECTEDUser rejected the send / sign in the wallet
WALLET_TRANSFER_INVALID_TOKENToken does not belong to that wallet / request
WALLET_TRANSFER_NAMESPACE_MISMATCHToken network does not match the connection
WALLET_TRANSFER_NO_ROUTENo deposit route (plan is unavailable, or destination is missing)
WALLET_TRANSFER_INVALID_AMOUNTAmount missing, not parseable, or not positive
WALLET_TRANSFER_QUOTE_FAILEDQuote (or min conversion) failed
WALLET_TRANSFER_EXECUTE_FAILEDSubmit failed after leaving the wallet
WALLET_TRANSFER_INSUFFICIENT_FEENot enough native token to cover fees
WALLET_TRANSFER_REGISTER_FAILEDThe wallet already sent; registering with Swapped failed again on retry()
WALLET_TRANSFER_REQUIRES_RETRYsubmit called after a previous submit already returned requires_retry
WALLET_TRANSFER_NO_PENDING_RETRYretry() called with nothing to retry
SESSION_NOT_ACTIVESession cannot accept a new payment
SESSION_REQUIREDNo loaded session

validateAmount returns { ok: false, code } instead of throwing (BELOW_MIN, INVALID_AMOUNT, WRONG_FLOW).

Unmapped HTTP failures surface as API_ERROR.

React

Hooks that require WalletsProvider throw REACT_WALLETS_PROVIDER_REQUIRED when used outside it.