# Get All Possible Routes

## Get Best Routes API

It goes through all the possible [swappers](https://docs.rango.exchange/terminology#swapper) to find a list of best possible routes for swapping X to Y.

{% tabs %}
{% tab title="Typescript (SDK)" %}

```typescript
const bestRoutes = await rango.getAllRoutes({
    from: {"blockchain": "BSC", "symbol": "BNB", "address": null},
    to: {"blockchain": "AVAX_CCHAIN", "symbol": "USDT.E", "address": "0xc7198437980c041c805a1edcba50c1ce5db95118"},    
    amount: "1",
    slippage: "1.0"
})
```

{% endtab %}

{% tab title="Node.js (Axios)" %}

```typescript
const response = await axios.post(
  'https://api.rango.exchange/routing/bests',
  {
    'from': {
      'blockchain': 'BSC',
      'symbol': 'BNB'
    },
    'to': {
      'blockchain': 'AVAX_CCHAIN',
      'symbol': 'USDT.E',
      'address': '0xc7198437980c041c805a1edcba50c1ce5db95118'
    },
    'amount': '1',
    'slippage': '1.0'
  },
  {
    params: {
      'apiKey': 'c6381a79-2817-4602-83bf-6a641a409e32'
    },
    headers: {
      'content-type': 'application/json'
    }
  }
);
```

{% endtab %}

{% tab title="Bash (cURL)" %}

```bash
curl --request POST \
     --url 'https://api.rango.exchange/routing/bests?apiKey=c6381a79-2817-4602-83bf-6a641a409e32' \
     --header 'content-type: application/json' \
     --data '
{
  "from": {
    "blockchain": "BSC",
    "symbol": "BNB"
  },
  "to": {
    "blockchain": "AVAX_CCHAIN",
    "symbol": "USDT.E",
    "address": "0xc7198437980c041c805a1edcba50c1ce5db95118"
  },
  "amount": "1",
  "slippage": "1.0"
}
'
```

{% endtab %}
{% endtabs %}

{% embed url="<https://rango-api.readme.io/reference/getbestroutes>" %}
Get All Routes Swagger
{% endembed %}

{% hint style="info" %}
**Confirm User Selected Route**&#x20;

When user confirms one of the routes and you want to go to the next step (creating transaction), it's required to call the [confirm route](https://docs.rango.exchange/api-integration/main-api-multi-step/api-reference/confirm-route) with the relevant route request Id. Otherwise, Rango won't create the transaction for you.
{% endhint %}

{% hint style="info" %}
**How to filter blockchains and swappers of the route?**

These parameters are used to limit blockchains of your interest, swappers, types of transactions, complexity of implementation, etc:

* `swappers`, `swappersExclude`
* `swapperGroups`, `swapperGroupsExclude`
* `blockchains`, `blockchainsExclude`
* `transactionTypes`

\
**Example 1.** Imagine that you are developing a dApp which only supports EVM and Solana. You could pass the `transactionTypes` equals to `['EVM', 'SOLANA']`.

**Example 2.** Imagine that you want to only support some specific bridges and dexes in your dApp. you could simply pass the `swapperGroups` equals to list of those swappers. e.g. you could pass `['Hyphen', 'Synapse Swapper', '1Inch', 'UniSwap']`.

**Example 3.** In multi-step routing, the optimal route may not always be a single step, and intermediary blockchains are chosen based on the best price for the route. By using blockchain parameters, you can control which blockchains are involved in the route. e.g. you could pass `blockchains` equals to `['ETH',  'BSC', 'ARBITRUM', 'POLYGON']`.&#x20;
{% endhint %}

### Best Routes Request&#x20;

{% tabs %}
{% tab title="API Definition" %}

* **`from`** <mark style="color:red;">\*</mark>  Asset
  * Description: The source [asset](https://docs.rango.exchange/terminology#asset-token)
  * Example: `{"blockchain": "BSC", "symbol": "BNB", "address": null}`
* **`to`** <mark style="color:red;">\*</mark>  Asset
  * Description: The destination [asset](https://docs.rango.exchange/terminology#asset-token)
  * Example:  `{"blockchain": "AVAX_CCHAIN", "symbol": "USDT.E", "address": "0xc7198437980c041c805a1edcba50c1ce5db95118"}`
* **`amount`** <mark style="color:red;">\*</mark> String
  * Description: The human-readable amount of asset *from* that is going to be swapped.
  * Example: `0.28`
* **`connectedWallets`**
  * Description: Optional list of all connected wallets of user in all blockchains.&#x20;
* **`slippage`** number
  * Description: Amount of user's preferred slippage in percent. if you don't send it, it will assume 0.5% slippage. (It's used to filter the swappers or routes that are not suitable for the given slippage)
* **`contractCall`** Boolean
  * Description: set this parameter to `true` if you want to send transactions through a contract. It will filter swappers that are not possible to be called by another contract.
  * **Caution:** if you call Rango contracts using your contract and your contract is not white listed in some underlying protocols like Thorchain, user fund may stuck forever in Thorchain contracts. In this case, you need to exclude these swappers using this flag or ask related protocols to white list your contract.
  * Example: `true`
* **`affiliateRef`** String
  * Description: The [affiliate unique key](https://docs.rango.exchange/terminology#affiliate-ref-referrer-code). In the Rango Exchange App, an affiliate key is generated using a wallet address, and this same wallet address is used to receive the fee charged by the dApp for the request.
  * Example: `K3ldk3`
* **`affiliatePercent`** String
  * Description: The dApp transaction fee in percent. Rango allows affiliate percent up to maximum of 3.0 percent.&#x20;
  * Example: `1.5` which means 1.5 percent of the input amount&#x20;
* **`affiliateWallets`**
  * Description: List of affiliate wallets per blockchain for referral rewards. If this parameter is not provided, the wallet used for generating the `affiliateRef` will be used. By passing this parameter, you can override the wallet address used for the dApp transaction fee for each blockchain.&#x20;
* **`disableMultiStepTx`** Boolean
  * Description: Some bridges requires more than one transaction for each swap. For example, some bridges require transaction on both source and destination blockchains by the users. Using this flag, you could enable routing via these protocols. Default is true.
  * **Note:** At the moment, only Voyager bridge subjects to this condition.&#x20;
  * Default: `true`
* **`blockchains`** String
  * Description: Pass comma separated list of blockchains if you want to filter meta blockchains to some specific ones.
  * Example: `POLYGON,ETH`
* **`blockchainsExclude`** Boolean
  * Description: A boolean value indicating whether the specified blockchains should be excluded or included in the response.
  * Example: `true`
* **`swappers`** String
  * Description: Pass comma separated list of swappers if you want to filter meta swappers to some specific ones.
  * Example: `Across,OneInchEth`
* **`swappersExclude`** Boolean
  * Description: A boolean value indicating whether the specified swappers should be excluded or included in the response.
  * Example: `false`
* **`swappersGroups`** String
  * Description: Pass comma separated list of swapper groups if you want to filter meta swapper groups to some specific ones.
  * Example: `Across,1Inch`
* **`swappersGroupsExclude`** Boolean
  * Description: A boolean value indicating whether the specified swapper groups should be excluded or included in the response.
  * Example: `false`
* **`transactionTypes`** String
  * Description: Pass comma separated list of transaction types if you want to filter blockchains types to some specific ones.
  * Example: `EVM,COSMOS`
* **`transactionTypesExclude`** Boolean
  * Description: A boolean value indicating whether the specified transaction types should be excluded or included in the response.
  * Example: `false`
* **`enableCentralizedSwappers`** Boolean
  * Description: Set this flag to true if you want to enable routing through the centralized solutions and obtain the associated metadata, including related swappers and tokens. The default value for this argument is false.
  * **Caution:** To enable these swappers, you must pass the user's IP to the Rango API for compliance checks. Additionally, user funds may be held for KYC if their wallet is flagged as risky by the screening solutions implemented by these protocols.
  * Default: `false`
* **`avoidNativeFee`**&#x42;oolean
  * Description: When this condition is true, swappers that charge fees in native tokens will be excluded. For instance, when called from an AA account.\
    Swappers like Stargate charge user fees in native tokens instead of the input amount, causing the transaction value to differ from the user's input amount. Alternatively, the user may need to transfer native tokens in a contract call to cover these protocol fees. Although you can disable these protocols using this flag, we do not recommend it as it reduces the coverage of routes.
  * Default: `false`
* **`interChainMessage`**
  * Description: Info about inter-chain message (Source & Destination contracts and IM Message) for cross-chain messaging.
* **`messagingProtocols`**
  * Description: List of messaging protocols to be used for passing interchain messages.
    {% endtab %}

{% tab title="SDK Models (Typescript)" %}

```typescript
export type MultiRouteRequest = Omit<
  BestRouteRequest, 
  'selectedWallets' | 'destination' | 'checkPrerequisites' | 'forceExecution' | 'maxLength'
>

export type BestRouteRequest = {
  from: Asset
  to: Asset
  amount: string
  selectedWallets: { [key: string]: string }
  connectedWallets?: UserWalletBlockchain[] | null
  checkPrerequisites?: boolean
  slippage?: string
  destination?: string
  forceExecution?: boolean
  affiliateRef?: string | null
  affiliatePercent?: number | null
  affiliateWallets?: { [key: string]: string }
  disableMultiStepTx?: boolean
  blockchains?: string[]
  swappers?: string[]
  swappersExclude?: boolean
  swapperGroups?: string[]
  swappersGroupsExclude?: boolean
  transactionTypes?: TransactionType[]
  messagingProtocols?: string[]
  maxLength?: number
  experimental?: boolean
  contractCall?: boolean
  interChainMessage?: InterChainMessage | null
  enableCentralizedSwappers?: boolean
  avoidNativeFee?: boolean
}

export type UserWalletBlockchain = {
  blockchain: string
  addresses: string[]
}

export enum TransactionType {
  EVM = 'EVM',
  TRANSFER = 'TRANSFER',
  COSMOS = 'COSMOS',
  SOLANA = 'SOLANA',
  TRON = 'TRON',
  STARKNET = 'STARKNET',
  TON = 'TON',
}

export type InterChainMessage = {
  sourceContract: string
  destinationContract: string
  imMessage: string
}
```

{% endtab %}
{% endtabs %}

### Best Routes Response&#x20;

{% tabs %}
{% tab title="API Definition" %}

* **`routeId`**
  * The unique request Id which is generated for this request by the server.
  * Example: `d10657ce-b13a-405c-825b-b47f8a5016ad`
* **`requestAmount`**
  * Description: The human readable input amount from the request.
* **`from`**
  * Description: The source asset.
* **`to`**
  * Description: The destination asset.
* **`results`**
  * Description: list of of all possible routes.
* **`diagnosisMessages`**
  * Description: A list of string messages that might be the cause of not finding the route. It's just for display purposes.
* **`missingBlockchains`**
  * Description: 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`**
  * Description: List of all accepted blockchains, an empty list means no filter is required.
* **`processingLimitReached`**
  * Description: 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.
* **`walletNotSupportingFromBlockchain`**
  * Description: A warning indicating that none of your wallets have the same blockchain as X asset.
* **`error`**
  * Description: Error occurred during the operation.
* **`errorCode`**
  * Description: Error code shows the type of error.
* **`traceId`**
  * Description: Trace Id helps Rango support team to trace an issue.
    {% endtab %}

{% tab title="SDK Models (Typescript)" %}

```typescript
export type MultiRouteResponse = {
  from: Asset
  to: Asset
  requestAmount: string
  routeId: string
  results: MultiRouteSimulationResult[]
  diagnosisMessages: string[]
  error: string | null
  errorCode: number | null
  traceId: number | null
}

export type Asset = {
  blockchain: string
  address: string | null
  symbol: string
}

export type MultiRouteSimulationResult = {
  requestId: string
  outputAmount: string
  resultType: RoutingResultType
  swaps: SwapResult[]
  scores: { preferenceType: PreferenceType; score: number }[]
  tags: RouteTag[]
  missingBlockchains: string[] 
  walletNotSupportingFromBlockchain: boolean
}

export enum RoutingResultType {
  OK = 'OK',
  HIGH_IMPACT = 'HIGH_IMPACT',
  NO_ROUTE = 'NO_ROUTE',
  INPUT_LIMIT_ISSUE = 'INPUT_LIMIT_ISSUE',
  HIGH_IMPACT_FOR_CREATE_TX = 'HIGH_IMPACT_FOR_CREATE_TX',
}

export type PreferenceType = 'FEE' | 'SPEED' | 'PRICE' | 'NET_OUTPUT' | 'SMART'

export type RouteTag = { label: string; value: TagValue }

export type Tag =
  | 'RECOMMENDED'
  | 'FASTEST'
  | 'LOWEST_FEE'
  | 'HIGH_IMPACT'
  | 'CENTRALIZED'
  
export type TagValue = Tag | Omit<string, Tag>

export type SwapResult = {
  swapperId: string
  swapperLogo: string
  swapperType: SwapperType
  swapChainType: 'INTER_CHAIN' | 'INTRA_CHAIN'
  from: SwapResultAsset
  to: SwapResultAsset
  toAmount: string
  fromAmount: string
  fromAmountMaxValue: string | null
  fromAmountMinValue: string | null
  fromAmountPrecision: string | null
  fromAmountRestrictionType: AmountRestrictionType
  routes: SwapRoute[] | null
  internalSwaps: SwapResult[] | null
  fee: SwapFee[]
  estimatedTimeInSeconds: number
  timeStat: TimeStat | null
  includesDestinationTx: boolean
  maxRequiredSign: number
  recommendedSlippage: RecommendedSlippage | null
  warnings: string[]
}

export type SwapperType = 'BRIDGE' | 'DEX' | 'AGGREGATOR' | 'OFF_CHAIN'

export type SwapResultAsset = {
  blockchain: string
  address: string | null
  symbol: string
  logo: string
  blockchainLogo: string
  decimals: number
  usdPrice: number | null
}

export type AmountRestrictionType = 'INCLUSIVE' | 'EXCLUSIVE'

export type SwapRoute = {
  nodes: SwapSuperNode[] | null
}
  
export type SwapFee = {
  name: string
  expenseType: ExpenseType
  asset: Asset
  amount: string
  price: number | null
  meta: EVMFeeMeta | null
}

export type EVMFeeMeta = {
  type: "EvmNetworkFeeMeta",
  gasLimit: string,
  gasPrice: string
}

export type TimeStat = {
  min: number
  avg: number
  max: number
}

export type RecommendedSlippage = {
  error: boolean
  slippage: string
}

```

{% endtab %}

{% tab title="Sample Response" %}

```typescript
{
  "from": {
    "blockchain": "BSC",
    "symbol": "BNB",
    "address": null
  },
  "to": {
    "blockchain": "AVAX_CCHAIN",
    "symbol": "USDT.E",
    "address": "0xc7198437980c041c805a1edcba50c1ce5db95118"
  },
  "requestAmount": "1",
  "routeId": "9fd9efeb-fca2-41b2-87d0-43647345c311",
  "results": [
    {
      "requestId": "486c26c0-fd2f-448d-b096-a58354ed9649",
      "outputAmount": "492.147292",
      "swaps": [
        {
          "swapperId": "BSCPancakeV3",
          "swapperLogo": "https://raw.githubusercontent.com/rango-exchange/assets/main/swappers/Pancake/icon.svg",
          "swapperType": "DEX",
          "from": {
            "symbol": "BNB",
            "logo": "https://rango.vip/tokens/ALL/BNB.png",
            "blockchainLogo": "https://raw.githubusercontent.com/rango-exchange/assets/main/blockchains/BSC/icon.svg",
            "address": null,
            "blockchain": "BSC",
            "decimals": 18,
            "usdPrice": 493.27
          },
          "to": {
            "symbol": "USDC",
            "logo": "https://rango.vip/i/e4x0s8",
            "blockchainLogo": "https://raw.githubusercontent.com/rango-exchange/assets/main/blockchains/BSC/icon.svg",
            "address": "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
            "blockchain": "BSC",
            "decimals": 18,
            "usdPrice": 0.999239
          },
          "fromAmount": "1.000000000000000000",
          "fromAmountPrecision": null,
          "fromAmountMinValue": null,
          "fromAmountMaxValue": null,
          "fromAmountRestrictionType": null,
          "toAmount": "492.760964860255103480",
          "fee": [
            {
              "asset": {
                "blockchain": "BSC",
                "symbol": "BNB",
                "address": null
              },
              "expenseType": "DECREASE_FROM_OUTPUT",
              "amount": "0.0015000000000000000000",
              "name": "Rango Fee",
              "price": 493.27
            },
            {
              "asset": {
                "blockchain": "BSC",
                "symbol": "BNB",
                "address": null
              },
              "expenseType": "FROM_SOURCE_WALLET",
              "amount": "0.000406595200000000",
              "name": "Network Fee",
              "meta": {
                "type": "EvmNetworkFeeMeta",
                "gasLimit": "369632",
                "gasPrice": "1100000000"
              },
              "price": 493.27
            }
          ],
          "estimatedTimeInSeconds": 45,
          "swapChainType": "INTER_CHAIN",
          "routes": [
            {
              "nodes": [
                {
                  "nodes": [
                    {
                      "marketName": "BSCPancakeV3",
                      "marketId": "BSCPancakeV3",
                      "percent": 1.0,
                      "pools": [
                        "0xf2688fb5b81049dfb7703ada5e770543770612c4"
                      ],
                      "inputAmount": "998500000000000000",
                      "outputAmount": "492760964860255103480"
                    }
                  ],
                  "from": "BNB",
                  "fromLogo": "",
                  "fromAddress": null,
                  "fromBlockchain": "BSC",
                  "to": "USDC",
                  "toLogo": "",
                  "toAddress": "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
                  "toBlockchain": "BSC"
                }
              ]
            }
          ],
          "recommendedSlippage": null,
          "warnings": [],
          "timeStat": {
            "min": 1,
            "avg": 45,
            "max": 203
          },
          "includesDestinationTx": false,
          "internalSwaps": null,
          "maxRequiredSign": 1
        },
        {
          "swapperId": "XY Finance",
          "swapperLogo": "https://raw.githubusercontent.com/rango-exchange/assets/main/swappers/XY Finance/icon.svg",
          "swapperType": "BRIDGE",
          "from": {
            "symbol": "USDC",
            "logo": "https://rango.vip/i/e4x0s8",
            "blockchainLogo": "https://raw.githubusercontent.com/rango-exchange/assets/main/blockchains/BSC/icon.svg",
            "address": "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
            "blockchain": "BSC",
            "decimals": 18,
            "usdPrice": 0.999239
          },
          "to": {
            "symbol": "USDC",
            "logo": "https://rango.vip/i/j9eYAa",
            "blockchainLogo": "https://raw.githubusercontent.com/rango-exchange/assets/main/blockchains/AVAX_CCHAIN/icon.svg",
            "address": "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
            "blockchain": "AVAX_CCHAIN",
            "decimals": 6,
            "usdPrice": 1.0
          },
          "fromAmount": "492.760964860255103480",
          "fromAmountPrecision": null,
          "fromAmountMinValue": "0.215999999999999992006394222698872908949851989746093750",
          "fromAmountMaxValue": "4245.273839",
          "fromAmountRestrictionType": "EXCLUSIVE",
          "toAmount": "492.539528",
          "fee": [
            {
              "asset": {
                "blockchain": "BSC",
                "symbol": "USDC",
                "address": "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d"
              },
              "expenseType": "DECREASE_FROM_OUTPUT",
              "amount": "0.2214360964860255103480",
              "name": "Swapper Fee",
              "price": 0.999239
            },
            {
              "asset": {
                "blockchain": "BSC",
                "symbol": "BNB",
                "address": null
              },
              "expenseType": "FROM_SOURCE_WALLET",
              "amount": "0.000205356800000000",
              "name": "Network Fee",
              "meta": {
                "type": "EvmNetworkFeeMeta",
                "gasLimit": "186688",
                "gasPrice": "1100000000"
              },
              "price": 493.27
            }
          ],
          "estimatedTimeInSeconds": 180,
          "swapChainType": "INTRA_CHAIN",
          "routes": null,
          "recommendedSlippage": null,
          "warnings": [],
          "timeStat": {
            "min": 59,
            "avg": 177,
            "max": 543
          },
          "includesDestinationTx": false,
          "internalSwaps": null,
          "maxRequiredSign": 1
        },
        {
          "swapperId": "AvaxChainV3",
          "swapperLogo": "https://raw.githubusercontent.com/rango-exchange/assets/main/swappers/UniSwapV2/icon.svg",
          "swapperType": "DEX",
          "from": {
            "symbol": "USDC",
            "logo": "https://rango.vip/i/j9eYAa",
            "blockchainLogo": "https://raw.githubusercontent.com/rango-exchange/assets/main/blockchains/AVAX_CCHAIN/icon.svg",
            "address": "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
            "blockchain": "AVAX_CCHAIN",
            "decimals": 6,
            "usdPrice": 1.0
          },
          "to": {
            "symbol": "USDT.E",
            "logo": "https://rango.vip/i/GJxbOP",
            "blockchainLogo": "https://raw.githubusercontent.com/rango-exchange/assets/main/blockchains/AVAX_CCHAIN/icon.svg",
            "address": "0xc7198437980c041c805a1edcba50c1ce5db95118",
            "blockchain": "AVAX_CCHAIN",
            "decimals": 6,
            "usdPrice": 1.0
          },
          "fromAmount": "492.539528",
          "fromAmountPrecision": null,
          "fromAmountMinValue": null,
          "fromAmountMaxValue": null,
          "fromAmountRestrictionType": null,
          "toAmount": "492.147292",
          "fee": [
            {
              "asset": {
                "blockchain": "AVAX_CCHAIN",
                "symbol": "AVAX",
                "address": null
              },
              "expenseType": "FROM_SOURCE_WALLET",
              "amount": "0.010380480000000000",
              "name": "Network Fee",
              "meta": {
                "type": "EvmNetworkFeeMeta",
                "gasLimit": "377472",
                "gasPrice": "27500000000"
              },
              "price": 21.53
            }
          ],
          "estimatedTimeInSeconds": 60,
          "swapChainType": "INTER_CHAIN",
          "routes": [
            {
              "nodes": [
                {
                  "nodes": [
                    {
                      "marketName": "AvaxChainV3",
                      "marketId": "AvaxChainV3",
                      "percent": 1.0,
                      "pools": [
                        "0xb2dc1235bf4b36628a8665aeb668bf202759528a"
                      ],
                      "inputAmount": "492539528",
                      "outputAmount": "492147292"
                    }
                  ],
                  "from": "USDC",
                  "fromLogo": "",
                  "fromAddress": "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
                  "fromBlockchain": "AVAX_CCHAIN",
                  "to": "USDT.E",
                  "toLogo": "",
                  "toAddress": "0xc7198437980c041c805a1edcba50c1ce5db95118",
                  "toBlockchain": "AVAX_CCHAIN"
                }
              ]
            }
          ],
          "recommendedSlippage": null,
          "warnings": [],
          "timeStat": {
            "min": 2,
            "avg": 47,
            "max": 360
          },
          "includesDestinationTx": false,
          "internalSwaps": null,
          "maxRequiredSign": 1
        }
      ],
      "resultType": "OK",
      "scores": [
        {
          "preferenceType": "NET_OUTPUT",
          "score": 100
        },
        {
          "preferenceType": "FEE",
          "score": 72
        },
        {
          "preferenceType": "SPEED",
          "score": 48
        },
        {
          "preferenceType": "PRICE",
          "score": 100
        },
        {
          "preferenceType": "SMART",
          "score": 100
        }
      ],
      "tags": [
        {
          "label": "Recommended",
          "value": "RECOMMENDED"
        }
      ],
      "walletNotSupportingFromBlockchain": false,
      "missingBlockchains": []
    },
  ],
  "diagnosisMessages": [],
  "error": null,
  "errorCode": null,
  "traceId": null
}
```

{% endtab %}
{% endtabs %}
