Track swap progress with onEvent and read the IntentResult a swap resolves with.
Pass options.onEvent to swapWithExactIn() or swapWithExactOut() to receive IntentEvent updates. The SDK catches errors thrown by your callback, so a failing handler never interrupts the swap.
When a plan step starts, completes, or fails. state is 'started', 'completed', or 'failed'.
status
intentId, status, substatus, legs
On each fill status poll. status is 'created', 'deposited', 'fulfilled', or 'expired'.
Each entry in legs describes one source: sourceIndex, status, and optional txHash, txExplorerUrl, protocolExplorerUrl, and error.
Example
TypeScript
import type { IntentEvent, IntentQuote, SwapExactInParams } from '@avail-project/nexus-core';declare const params: SwapExactInParams;declare function showQuote(quote: IntentQuote): void;declare function setStep(type: string, state: string): void;declare function showError(message?: string, code?: string, committed?: boolean): void;declare function setFillStatus(intentId: string, status: string): void;declare function setLegLink(sourceIndex: number, url?: string): void;const onEvent = (event: IntentEvent) => { switch (event.type) { case 'quote': showQuote(event.quote); break; case 'step': setStep(event.step.type, event.state); if (event.state === 'failed') { showError(event.errorDetails?.message, event.errorDetails?.code, event.committed); } break; case 'status': setFillStatus(event.intentId, event.status); for (const leg of event.legs) setLegLink(leg.sourceIndex, leg.txExplorerUrl); break; }};await client.swapWithExactIn(params, { onEvent });
Events report progress only. Catch the promise to handle the final outcome.
Plan steps
quote.plan.steps lists the steps for that quote, and step events reference them.
step.type
Extra fields
Wallet action
erc20_approval
chainId, tokenAddress, spender, amountRaw
Approval transaction for the minimum required amount
source_approval_signature
chainId, tokenAddress, spender, amountRaw
Typed-data signature that authorizes the source token
intent_signature
none
Signature over the intent
native_transaction
chainId, sourceIndex, to, valueRaw
Native-token deposit transaction
intent_submission
none
None. The SDK submits the intent.
intent_fulfillment
none
None. The SDK waits for the fill.
Committed attempts
committed becomes true once the attempt can settle even if a later step fails: after the intent signature when an ERC-20 source is used, or after a native deposit is broadcast.
If a step fails with committed: true, the intent may still fill. Check listIntents() or the explorer before retrying, or the user may pay twice.
Step errors
A failed step event carries errorDetails (IntentStepError): name, message, and optional code, category, service, stepId, stepType, chainId, and details. Match on code, not message.
Result
Both swap methods resolve with IntentResult after the fill.