Routing API

Get the best route for swapping X to Y

Get Best Route

It goes through all the possible DEX & bridges to find the best possible route based on user experience, fee amount, and output of swap.

const bestRoute = await rangoClient.getBestRoute({
    amount: "1",
    from: {"blockchain": "BSC", "symbol": "BNB", "address": null},
    to: {"blockchain": "TERRA", "symbol": "Luna", "address": null},
    checkPrerequisites: false,
    connectedWallets: [
        {blockchain: "TERRA", addresses: ["terra18vnrzlzm2c4xfsx382pj2xndqtt00rvhu24sqe"]},
        {blockchain: "BSC", addresses: ["0xeae6d42093eae057e770010ffd6f4445f7956613"]}
    ],
    selectedWallets: {
        "TERRA": "terra18vnrzlzm2c4xfsx382pj2xndqtt00rvhu24sqe",
        "BSC": "0xeae6d42093eae057e770010ffd6f4445f7956613",
    },
})

It is recommended to set checkPrerequisitesto false when you want to just give the user the best route preview and mark it as true when the user wants to do the actual swap.

There are extra parameters to limit blockchains of your interest, DEX/bridges list, types of transactions, complexitiy of implementation, etc.

Best Route Request

ParamDescription

from *

The source asset

to *

The destination asset

amount *

The human-readable amount of asset X that is going to be swapped, e.g. 0.28

checkPrerequisites *

It should be false when a client just likes to preview the route to the user, and true when the user really accepted to swap.

If true, the server will be much slower to respond but will check some pre-requisites including balance of X and required fees in user's wallets.

connectedWallets *

List of all user connected wallet addresses per each blockchain.

selectedWallets *

Map of blockchain to the selected address.

affiliateRef

The affiliate ref that client likes to send to Rango, so in cases of 1inch, Thorchain, etc. that support affiliation, the referrer will earn some money if the user accepts the route and signs the transactions. e.g. K3ldk3

maxLength

Maximum number of steps allowed in best route response

disableMultiStepTx

It should be true when the client doesn't want multi-step transactions.

blockchains

List of all accepted blockchains, an empty list means no filter is required.

swappers

List of all accepted swappers, an empty list means no filter is required.

transactionTypes

List of all accepted transaction types including EVM, TRANSFER and COSMOS

Best Route Response

FieldDescription

requestId

The unique request Id which is generated for this request by the server. It should be passed down to all other endpoints if this swap continues on. e.g. d10657ce-b13a-405c-825b-b47f8a5016ad

requestAmount

The human readable input amount from the request

from

The source asset

to

The destination asset

result

The swap result route

validationStatus

Pre-requisites check result. It will be null if the request checkPrerequisites was false

diagnosisMessages

List of string messages that might be the cause of not finding the route. It's just for display purposes.

missingBlockchains

List of all blockchains which are necessary to be present for the best route and the user has not provided any connected wallets for it. A null or empty list indicates that there is no problem.

blockchains

List of all accepted blockchains, an empty list means no filter is required.

processingLimitReached

A warning indicates that it took too much time to find the best route and the server could not find any routes from X to Y.

Last updated