TokenFlight
Open app

Events

What you can listen for, and error codes.

Events are optional. Most sites only need these three:

ts

widget.on("orderCreated", ({ orderId }) => save(orderId));
widget.on("orderCompleted", ({ orderId, outcome }) => console.log(orderId, outcome)); // filled | partial | unfilled
widget.on("error", ({ code, message }) => console.warn(code, message));

widget.on(name, handler) returns a function that removes the handler. A listener that throws does not break the others. Payloads carry ids, states, tokens and amounts, never keys or signatures. Amounts are in the token's smallest unit, and a token or side is { chainId, token, symbol, decimals, amount }.

All events

EventData
readyversion. The frame loaded and speaks a compatible protocol.
quotespend, receive. A quote arrived for the form.
orderCreatedorderId, spend, receive, depositor, payout, refund.
depositSubmittedorderId, txHash, chainId. The deposit was sent from the user's wallet; the hash is the source chain's transaction.
orderStateorderId, state.
orderCompletedorderId, outcome (filled, partial or unfilled), spend, received, refunded.
orderFailedorderId. The order finished but its delivery failed.
errorcode, message.

Error codes

CodeMeaning
READY_TIMEOUTThe page did not answer in time: wrong address, or your origin is not allowed on that deployment. A page that answers later is still accepted.
PROTOCOL_MISMATCHThe page and the SDK speak different protocol versions. Upgrade both together.
PAGE_CRASHThe page hit an error and is showing its own message.
TOKEN_NOT_SUPPORTEDA fromToken or toToken you passed is not offered by this deployment, so that side was left empty.
numericA quote failed; the code is the HTTP status the service answered with.
On READY_TIMEOUT and PROTOCOL_MISMATCH the widget itself shows a short message in your container (with a "Try again" button for a timeout), so you do not have to handle them. widget.reload() does the same as that button.

Recovering an order

Local storage inside a third-party frame can be partitioned or blocked. A host that wants recovery keeps the id from orderCreated and initializes again with config.orderId; the page then opens that order's tracking view.