Skip to main content
Use this recipe for the quote section of a swap form. One request compares enabled sources. You don’t need to send a separate request to each provider.

Request a quote

This Node.js 20+ example quotes 0.001 ETH into ROUTE on Robinhood Chain. It only reads a quote; it does not build or submit a transaction.
The output amounts above are base-unit strings. Get the output token’s decimals from the token endpoint before formatting them for a user.

Read the result

A failed or unverified candidate should not look like a ready-to-sign alternative. Use selected to identify Route’s choice instead of sorting only by the original output estimate. The comparison does not enumerate every pool or every possible route. netAmountOut subtracts a modeled gas cost in output-token units. It is useful for comparison, but it is not the number of tokens the contract must pay the user. Use the token output and the user’s slippage choice when setting a minimum.

Refresh as inputs change

Debounce amount edits, cancel superseded requests and ignore late responses for a previous token pair or amount. Clear the displayed quote when it expires. A later request must get a fresh quote even if the inputs are unchanged. To restrict a request to one source, add provider=route, provider=kyber or provider=zerox. Read enabledProviders from configuration first. Omitting provider compares the enabled sources. Honor Retry-After when the API is busy. Do not retry on every keystroke or silently increase the user’s slippage after an error. Next: Prepare a native-ETH swap demonstrates the direct provider. The wallet flow covers the checks required before signing.