Appearance
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
| Code | When |
|---|---|
WALLET_NOT_SUPPORTED | Payment method provider has no SDK wallet config |
WALLET_NOT_INSTALLED | Injected connect and the extension is not present |
WALLET_ALREADY_CONNECTED | Injected slot for that provider is already connected |
WALLET_CONNECT_REJECTED | User rejected the connect request in the wallet |
WALLET_NAMESPACE_UNSUPPORTED | Requested namespace is not available |
WALLET_CHAIN_UNSUPPORTED | Requested chain is not available |
WALLET_PAIRING_IN_PROGRESS | A WalletConnect pairing is already in flight |
WALLET_PAIRING_CANCELLED | In-flight pairing was cancelled |
WALLET_POPUP_BLOCKED | Browser blocked the connect popup |
WALLET_POPUP_CLOSED | Popup closed before connect finished |
WALLET_POPUP_IN_PROGRESS | Another popup connect is already open |
WALLET_POPUP_NO_OPENER | Popup could not reach the opener |
WALLET_GATEWAY_NOT_READY | Wallet host is not ready |
WALLET_SESSION_EXPIRED | WalletConnect session expired |
Transfer
| Code | When |
|---|---|
WALLET_NOT_CONNECTED | No connection for that walletId (or no address for the network) |
WALLET_TRANSACTION_REJECTED | User rejected the send / sign in the wallet |
WALLET_TRANSFER_INVALID_TOKEN | Token does not belong to that wallet / request |
WALLET_TRANSFER_NAMESPACE_MISMATCH | Token network does not match the connection |
WALLET_TRANSFER_NO_ROUTE | No deposit route (plan is unavailable, or destination is missing) |
WALLET_TRANSFER_INVALID_AMOUNT | Amount missing, not parseable, or not positive |
WALLET_TRANSFER_QUOTE_FAILED | Quote (or min conversion) failed |
WALLET_TRANSFER_EXECUTE_FAILED | Submit failed after leaving the wallet |
WALLET_TRANSFER_INSUFFICIENT_FEE | Not enough native token to cover fees |
WALLET_TRANSFER_REGISTER_FAILED | The wallet already sent; registering with Swapped failed again on retry() |
WALLET_TRANSFER_REQUIRES_RETRY | submit called after a previous submit already returned requires_retry |
WALLET_TRANSFER_NO_PENDING_RETRY | retry() called with nothing to retry |
SESSION_NOT_ACTIVE | Session cannot accept a new payment |
SESSION_REQUIRED | No 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.