Skip to main content

StatusCodes (enum)

Returned in responses (e.g. approval, trade) for programmatic handling:
import { StatusCodes } from "@dzapio/sdk";

StatusCodes.UserRejectedRequest;   // 4001 - User rejected in wallet
StatusCodes.Success;                // 200
StatusCodes.FunctionNotFound;      // 32771 - 0x8003
StatusCodes.Error;                  // 500
StatusCodes.WalletRPCFailure;      // 429
StatusCodes.SimulationFailure;     // 417
StatusCodes.ContractExecutionError; // -500

Trade failure actions (contractErrorActions)

When trade() fails, check result.action and handle accordingly:
ActionMeaningSuggested handling
TRY_ANOTHER_ROUTERecommended route failedRebuild data with protocol: bestReturnSource from the quote and call trade() again.
INCREASE_SLIPPAGESlippage too lowAsk user to increase slippage and retry.
INCREASE_ALLOWANCEAllowance insufficientRe-run allowance/approval flow and retry.
Example:
if (result.status !== TxnStatus.success && result.action === "TRY_ANOTHER_ROUTE") {
  const fallbackData = request.data.map((d, i) => {
    const pairKey = Object.keys(quotes)[i];
    const fallbackSource = quotes[pairKey]?.bestReturnSource;
    return fallbackSource ? { ...d, protocol: fallbackSource } : d;
  });
  result = await dZap.trade({ request: { ...request, data: fallbackData }, signer });
}

DZapTransactionResponse

The trade() response shape:
type DZapTransactionResponse = {
  status: TxnStatus;
  errorMsg?: string;
  code?: StatusCodes | number;
  action?: "TRY_ANOTHER_ROUTE" | "INCREASE_SLIPPAGE" | "INCREASE_ALLOWANCE";
  txnHash?: HexString;
  error?: unknown;
  additionalInfo?: Record<string, unknown>;
  updatedQuotes?: Record<string, unknown>;
};
Always check status === TxnStatus.success before using txnHash. Use errorMsg for user-facing messages.

Next steps