2️⃣Quote

Get the best route to swap X to Y

Using information retrieved from the meta, you could implement your own SwapBox including your blockchain and token selector. The next step is to show the preview of the best route possible when the user selects the source and the destination tokens.

// Converting 0.1 BSC BNB to AVAX_CCHAIN USDT.E 
const quote = await rangoClient.quote({
  from: {
    "blockchain": "BSC", 
    "symbol": "BNB", 
    "address": null
  },
  to: {
    "blockchain": "AVAX_CCHAIN", 
    "symbol": "USDT.E", 
    "address": "0xc7198437980c041c805a1edcba50c1ce5db95118"
  },
  amount: "100000000000000000" 
})

The blockchain and symbol names must be exactly what is fetched from Rango's metadata APIs. Check Metadata and Blockchains Metadata APIs regarding this.

You could call this method periodically to get the updated route before the user confirms the swap.

Asset Format

When dealing with asset formats, it's crucial to distinguish between native and non-native coins. Below is the format you should use for each type:

Native Coins

For native coins, the format is straightforward:

  • Format: Blockchain.Symbol

  • Example: BSC.BNB

This denotes the blockchain on which the native coin operates, followed by the symbol of the coin itself.

Non-Native Coins

Non-native coins, which are tokens not originally part of the blockchain's main network, follow a different format:

  • Format: Blockchain.Symbol--TokenAddress

  • Example: BSC.USDT--0x55d398326f99059ff775485246999027b3197955

This format includes the blockchain, the symbol of the token, and the token's address on the blockchain, separated by a double dash (--).

Please check this doc if you want to get complete details on important fields in the quote response including resultType, fee and amountRestriction.

pageQuote & Swap APIs

Here is a sample quote object you could get.

sample quote
{{
  "requestId": "a64f4851-f61f-4407-86c5-e37abd289d99",
  "resultType": "OK",
  "route": {
    "outputAmount": "24307447",
    "outputAmountMin": "24064980",
    "outputAmountUsd": 24.304634664703492,
    "swapper": {
      "id": "Hyphen Aggregator",
      "title": "Hyphen",
      "logo": "https://api.rango.exchange/swappers/hyphen.svg",
      "swapperGroup": "Hyphen",
      "types": [
        "AGGREGATOR"
      ],
      "enabled": true
    },
    "from": {
      "blockchain": "BSC",
      "symbol": "BNB",
      "name": null,
      "isPopular": false,
      "chainId": "56",
      "address": null,
      "decimals": 18,
      "image": "https://api.rango.exchange/tokens/ETH/BNB.png",
      "blockchainImage": "https://api.rango.exchange/blockchains/bsc.svg",
      "usdPrice": 243.71759113601925,
      "supportedSwappers": []
    },
    "to": {
      "blockchain": "AVAX_CCHAIN",
      "symbol": "USDT.E",
      "name": null,
      "isPopular": false,
      "chainId": "43114",
      "address": "0xc7198437980c041c805a1edcba50c1ce5db95118",
      "decimals": 6,
      "image": "https://api.rango.exchange/i/niIihm",
      "blockchainImage": "https://api.rango.exchange/blockchains/avax_cchain.svg",
      "usdPrice": 0.9998843014942496,
      "supportedSwappers": []
    },
    "fee": [
      {
        "token": {
          "blockchain": "BSC",
          "symbol": "BNB",
          "name": null,
          "isPopular": true,
          "chainId": "56",
          "address": null,
          "decimals": 18,
          "image": "https://api.rango.exchange/tokens/ETH/BNB.png",
          "blockchainImage": "https://api.rango.exchange/blockchains/bsc.svg",
          "usdPrice": 243.71759113601925,
          "supportedSwappers": [
            "Wormhole",
            "ParaSwap Bsc",
            "OneInchBsc",
            "Satellite",
            "PancakeSwapBsc",
            "Voyager",
            "cBridge v2.0"
          ]
        },
        "expenseType": "FROM_SOURCE_WALLET",
        "amount": "1037163600000000",
        "name": "Network Fee"
      }
    ],
    "feeUsd": 0.2527750142059618,
    "amountRestriction": {
      "min": "42359934341395595",
      "max": "239354192103808110634",
      "type": "EXCLUSIVE"
    },
    "estimatedTimeInSeconds": 75,
    "path": [
      {
        "swapper": {
          "id": "OneInchBsc",
          "title": "1Inch",
          "logo": "https://api.rango.exchange/swappers/1inch.svg",
          "swapperGroup": "1Inch",
          "types": [
            "DEX"
          ],
          "enabled": true
        },
        "swapperType": "DEX",
        "from": {
          "blockchain": "BSC",
          "symbol": "BNB",
          "name": null,
          "isPopular": false,
          "chainId": "56",
          "address": null,
          "decimals": 18,
          "image": "https://api.rango.exchange/tokens/ETH/BNB.png",
          "blockchainImage": "https://api.rango.exchange/blockchains/bsc.svg",
          "usdPrice": 243.71759113601925,
          "supportedSwappers": []
        },
        "to": {
          "blockchain": "BSC",
          "symbol": "USDT",
          "name": null,
          "isPopular": false,
          "chainId": "56",
          "address": "0x55d398326f99059ff775485246999027b3197955",
          "decimals": 18,
          "image": "https://tokens.1inch.io/0xdac17f958d2ee523a2206206994597c13d831ec7.png",
          "blockchainImage": "https://api.rango.exchange/blockchains/bsc.svg",
          "usdPrice": 0.999613,
          "supportedSwappers": []
        },
        "inputAmount": "99989999999999999",
        "expectedOutput": "24312998025437187460",
        "estimatedTimeInSeconds": 15
      },
      {
        "swapper": {
          "id": "Hyphen",
          "title": "Hyphen",
          "logo": "https://api.rango.exchange/swappers/hyphen.svg",
          "swapperGroup": "Hyphen",
          "types": [
            "BRIDGE"
          ],
          "enabled": true
        },
        "swapperType": "BRIDGE",
        "from": {
          "blockchain": "BSC",
          "symbol": "USDT",
          "name": null,
          "isPopular": false,
          "chainId": "56",
          "address": "0x55d398326f99059ff775485246999027b3197955",
          "decimals": 18,
          "image": "https://biconomy-public-assets.s3.amazonaws.com/tokens/usdt-icon.svg",
          "blockchainImage": "https://api.rango.exchange/blockchains/bsc.svg",
          "usdPrice": 0.999613,
          "supportedSwappers": []
        },
        "to": {
          "blockchain": "AVAX_CCHAIN",
          "symbol": "USDT.E",
          "name": null,
          "isPopular": false,
          "chainId": "43114",
          "address": "0xc7198437980c041c805a1edcba50c1ce5db95118",
          "decimals": 6,
          "image": "https://api.rango.exchange/i/niIihm",
          "blockchainImage": "https://api.rango.exchange/blockchains/avax_cchain.svg",
          "usdPrice": 0.9998843014942496,
          "supportedSwappers": []
        },
        "inputAmount": "24312998025437187460",
        "expectedOutput": "24307447",
        "estimatedTimeInSeconds": 60
      }
    ]
  },
  "error": null
}

Last updated