Error Handling

Every Wallet SDK method throws WalletsApiError on a non-2xx response, with status, body and headers; a network failure throws a TypeError instead.

WalletsApiError

All SDK methods throw WalletsApiError on non-2xx HTTP responses. It extends the native Error class with structured HTTP response data:

import { WalletsApiError } from "@tatumio/wallet-sdk";

try {
  const shares = await client.generateWallet();
} catch (err) {
  if (err instanceof WalletsApiError) {
    console.error(`HTTP ${err.status}: ${err.message}`);
    console.error("Response body:", err.body);
    // err.status     — HTTP status code (number)
    // err.statusText — HTTP status text (string | undefined)
    // err.body       — parsed response body (unknown)
    // err.headers    — response Headers object (Headers | undefined)
  }
}

err.message has the form <API> request failed with status <code>, followed by the error detail from the response body when there is one. Custodian calls (wallets.custodian) use the label Wallets API, for example:

Wallets API request failed with status 401

The error body format differs between API layers, so err.body is typed unknown. To read the detail from any of them, use extractErrorDetail(err.body), which returns the message string or undefined.

Common Errors

401 — Invalid API Key or Client Token

Cause: For custodian calls, the apiKey passed to TatumWalletsSdk is invalid or expired. For client-scoped calls, the token passed to initClient() (client API key or Client Session Token) is invalid or expired.

Fix: Verify your API key in the Tatum Dashboard. The key goes in apiKey, not as a header — the SDK handles auth headers internally. For an expired Client Session Token, mint a new one with createClientSession().

403 — Insufficient Permissions

Cause: The token used in initClient() doesn't have permission for the requested operation. A client token (client API key or Client Session Token) can only access that client's own data.

Fix: Run custodian operations through wallets.custodian with your Tatum API key. Use client tokens only with initClient(), for the client they belong to.

404 — Client or Wallet Not Found

Cause: The clientId or walletId doesn't exist in your custodian environment.

Fix: Verify the ID. IDs from staging environments don't work in production.

422 — Missing Signing Share

Cause: The share passed to sendAssets(), sign(), or rawSign() is invalid or doesn't correspond to the wallet.

Fix: Ensure you're passing the correct curve's share. For EVM chains, use SECP256K1. For Solana/Stellar, use ED25519.

422 — Unsupported Chain

Cause: The chain value is not in WalletChain.

Fix: Use the WalletChain enum rather than raw strings.

422 — Insufficient Funds

Cause: The wallet doesn't have enough balance for the transfer plus gas.

Fix: Check the wallet balance before sending. Gas sponsorship covers gas only, not the amount you send: it applies to account-abstracted clients on configured chains (see Gas Sponsorship). On Tron, the wallet always pays its own fees.

422 — Wallet Feature Disabled

Cause: The operation uses a feature that isn't enabled for this client's environment.

Fix: First check whether the SDK can switch the feature on for you. Key eject is enabled per wallet with wallets.custodian.enableEject(), and the client must fetch the shares before ejectableUntil passes (see Eject keys). Gas sponsorship is configured per chain with wallets.custodian.getGasSponsorshipChains() and updateGasSponsorship() (see Gas Sponsorship). For an environment-level feature that has no SDK method, contact Tatum support to enable that specific feature. This is about that one feature: access to Smart Wallets itself is self-service.

Errors Before a Request Is Sent

The SDK throws these errors itself, without sending a request, so they aren't WalletsApiError:

ErrorWhen
Error: apiKey is required for custodian / sdk.api operationsYou access wallets.custodian or wallets.api on an SDK created without apiKey
Error: Client token is requiredinitClient() gets an empty token
Error: Missing path parameter "<name>" for <path>A required path value is missing
WalletChainEndOfLifeErrorsign() or sendAssets() targets a chain that reached end of life, such as LISK_MAINNET; err.chain holds the chain ID
Error from reconstructPrivateKey()A share is malformed, or the derived key doesn't match the client share's public key
import { WalletChainEndOfLifeError } from "@tatumio/wallet-sdk";

try {
  await client.sendAssets({ body });
} catch (err) {
  if (err instanceof WalletChainEndOfLifeError) {
    console.error(`${err.chain}: ${err.message}`);
  }
}

Error Handling Pattern

import {
  WalletsApiError,
  extractErrorDetail,
  type SendAssetsBody,
  type WalletsClient,
} from "@tatumio/wallet-sdk";

async function safeSend(client: WalletsClient, body: SendAssetsBody) {
  try {
    return await client.sendAssets({ body });
  } catch (err) {
    if (!(err instanceof WalletsApiError)) throw err; // re-throw unexpected errors

    switch (err.status) {
      case 401:
        throw new Error("Authentication failed — check your Tatum API key or client token");
      case 422: {
        const detail = extractErrorDetail(err.body) ?? err.message;
        if (detail.includes("Insufficient")) {
          throw new Error("Insufficient balance for this transfer");
        }
        throw new Error(`Invalid request: ${detail}`);
      }
      case 429:
        throw new Error("Rate limit exceeded — retry after a delay");
      default:
        throw new Error(`Tatum API error (${err.status}): ${err.message}`);
    }
  }
}

Network Errors

If the fetch call itself fails (no response), a standard TypeError is thrown (not a WalletsApiError). Handle it separately:

try {
  await client.generateWallet();
} catch (err) {
  if (err instanceof WalletsApiError) {
    // HTTP error with a response
  } else if (err instanceof TypeError) {
    // Network failure — no response received
    console.error("Network error:", err.message);
  }
}

Did this page help you?