trade() fails, check result.action and handle accordingly:
Example:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
How to handle contractErrorActions when trade() fails.
trade() fails, check result.action and handle accordingly:
| Action | Meaning | Suggested handling |
|---|---|---|
TRY_ANOTHER_ROUTE | Recommended route failed | Rebuild data with protocol: bestReturnSource from the quote and call trade() again. |
INCREASE_SLIPPAGE | Slippage too low | Ask user to increase slippage and retry. |
INCREASE_ALLOWANCE | Allowance insufficient | Re-run allowance/approval flow and retry. |
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 });
}