Skip to main content
Hooks are exported from 0xtrails and require TrailsProvider inside a QueryClientProvider. See install.

Quote and execute

useQuote

Returns a live quote for a source and destination, and a send function that executes it. Amounts are human-readable decimal strings. Setting from.amount makes the quote exact input; setting to.amount makes it exact output.

useTrailsSendTransaction

Opens the widget modal for a destination you set in code, so the customer can pay for it from any token or chain. Pass the destination when you call sendTransaction.
to takes the same fields as useQuote. Add from to preselect the source token, chain, and amount; omit it to let the customer choose in the modal.

Balances, chains, and tokens

Card purchase limits

useMeldPurchaseLimits returns the smallest and largest amount a card or bank purchase accepts for a country, fiat currency, and destination token, before any quote is requested. Pass paymentMethodType to narrow the window to one payment method.
fiatLimits is null while loading or when no route offers the payment method; treat it as unknown and let the quote decide. The full response is returned as limits, and limitsForPaymentMethod(limits, method) narrows it to one method.

Earn

See earn for usage.

Track intents

Recover stuck funds

Some failed routes produce an automatic refund. Check refundTransaction on the intent receipt to confirm one was submitted. If funds remain at an intent address, useIntentRecover lets the owner sign and send a recovery transaction.

Errors

getPrettifiedErrorMessage(error) turns any SDK error into a message you can show the customer. The getIs...Error helpers, such as getIsUserRejectionError and getIsBalanceTooLowError, identify specific failures.