Get a route

Before you can send tokens or messages, you'll need to set your parameters.

Our /route endpoint finds a route to match your params and returns the necessary data required to execute it on chain.

Example: Swap 1 WETH from Goerli and receive axlUSDC on the Moonbeam network


const getRoute = async (params) => {
    const result = await axios.get('https://testnet.api.squidrouter.com/v1/route', {
        params: params,
        headers: {
          "x-integrator-id": "your-integrator-id",
        }
    });
    return result.data;
}

const params = {
  fromChain: 5, // Goerli
  fromToken: '0xc778417E063141139Fce010982780140Aa0cD5Ab', // WETH on Ropsten
  fromAmount: '100000000000000000', // 0.1 WETH
  toChain: 1287, // Moonbase Alpha
  toToken: '0xd1633f7fb3d716643125d6415d4177bc36b7186b', // axlUSDC on Moonmbeam
  fromAddress: '0x...', // ethers.signer.address; transaction sender address
  toAddress: '0x...', // the recipient's address
  slippage: 3, // 3 --> 3.00% slippage. SDK supports 2 decimals
  enableForecall: true // optional, defaults to true
}

const route = await getRoute(params);

Params are structured as a https://docs.0xsquid.com/appendix/types#getroute-1 object. A GetRoute object describes a desired any-to-any transfer. It is defined by the following interface:

Request Params:

PropertyDescription

fromChain

Source Chain ID

fromToken

Address of the sending tokens

fromAmount

Amount of tokens to be sent in WEI

toChain

Destination Chain ID

toToken

Address of the receiving tokens

fromAddress

Transaction sender address. Will be also used as a fallback address for the source chain

toAddress

The expected output address that will received the destination tokens

slippage

Route total slippage limit (0-1) (unsupported, default to 1)

enableForecall

Instant execution on the destination chain when set to true

collectFees

Integrators can pass in the the collectFees object to collect a fee on transactions

Request Headers:

PropertyDescription

x-integrator-id

Integrator Id for squid to keep track of partners, complete the form to acquire it

Example response

{
  "route": {
    "estimate": {
      "fromAmount": "100000000000000000",
      "sendAmount": "120750911",
      "toAmount": "9372288569234398583",
      "toAmountMin": "9372288569234398583",
      "route": {
        "fromChain": [
          {
            "type": "SWAP",
            "dex": {
              "chainName": "Ethereum",
              "dexName": "UniswapV2",
              "swapRouter": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
              "factory": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
              "isStable": false
            },
            "path": [
              "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
              "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
            ],
            "squidCallType": 2,
            "fromToken": {
              "chainId": 1,
              "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
              "name": "Wrapped ETH",
              "symbol": "WETH",
              "decimals": 18,
              "logoURI": "https://assets.coingecko.com/coins/images/2518/small/weth.png?1628852295",
              "coingeckoId": "weth"
            },
            "toToken": {
              "name": "USDCoin",
              "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
              "symbol": "USDC",
              "decimals": 6,
              "chainId": 1,
              "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
              "coingeckoId": "usd-coin"
            },
            "fromAmount": "100000000000000000",
            "toAmount": "120750911",
            "toAmountMin": "120205757",
            "exchangeRate": "1211.145994980039994222",
            "priceImpact": "0.3",
            "dynamicSlippage": 0.45146957433319646
          }
        ],
        "toChain": [
          {
            "type": "SWAP",
            "dex": {
              "chainName": "Avalanche",
              "dexName": "Curve_v2",
              "swapRouter": "0x890f4e345B1dAED0367A877a1612f86A1f86985f",
              "isStable": true
            },
            "path": [
              "0xfaB550568C688d5D8A52C7d794cb93Edc26eC0eC",
              "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E"
            ],
            "squidCallType": 1,
            "fromToken": {
              "chainId": 43114,
              "address": "0xfaB550568C688d5D8A52C7d794cb93Edc26eC0eC",
              "name": "Axelar USDC",
              "symbol": "axlUSDC",
              "decimals": 6,
              "logoURI": "https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png?1547042389",
              "coingeckoId": "axlusdc"
            },
            "toToken": {
              "chainId": 43114,
              "address": "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
              "decimals": 6,
              "name": "USD Coin",
              "symbol": "USDC",
              "logoURI": "https://raw.githubusercontent.com/pangolindex/tokens/main/assets/43114/0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E/logo_24.png",
              "coingeckoId": "usd-coin"
            },
            "fromAmount": "120750911",
            "toAmount": "120858815",
            "toAmountMin": "120737956",
            "exchangeRate": "1",
            "priceImpact": "-0.09",
            "dynamicSlippage": 0.1
          },
          {
            "type": "SWAP",
            "dex": {
              "chainName": "Avalanche",
              "dexName": "Pangolin",
              "swapRouter": "0xE54Ca86531e17Ef3616d22Ca28b0D458b6C89106",
              "factory": "0xefa94DE7a4656D787667C749f7E1223D71E9FD88",
              "isStable": false
            },
            "path": [
              "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
              "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7"
            ],
            "squidCallType": 1,
            "fromToken": {
              "chainId": 43114,
              "address": "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
              "decimals": 6,
              "name": "USD Coin",
              "symbol": "USDC",
              "logoURI": "https://raw.githubusercontent.com/pangolindex/tokens/main/assets/43114/0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E/logo_24.png",
              "coingeckoId": "usd-coin"
            },
            "toToken": {
              "chainId": 43114,
              "address": "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",
              "name": "Wrapped AVAX",
              "symbol": "WAVAX",
              "decimals": 18,
              "logoURI": "https://raw.githubusercontent.com/pangolindex/tokens/main/assets/43114/0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7/logo_24.png",
              "coingeckoId": "wrapped-avax"
            },
            "fromAmount": "120858815",
            "toAmount": "9372288569234398583",
            "toAmountMin": "9329975537925597215",
            "exchangeRate": "0.077784587532707266",
            "priceImpact": "0.3",
            "dynamicSlippage": 0.45146957433319646
          }
        ]
      },
      "feeCosts": [
        {
          "name": "Gas Receiver Fee",
          "description": "Estimated Gas Receiver fee",
          "percentage": "0",
          "token": {
            "chainId": 1,
            "address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
            "name": "Ethereum",
            "symbol": "ETH",
            "decimals": 18,
            "logoURI": "https://assets.coingecko.com/coins/images/279/small/ethereum.png?1595348880",
            "coingeckoId": "ethereum"
          },
          "amount": "503509582401222",
          "amountUSD": "0.3048"
        }
      ],
      "gasCosts": [
        {
          "type": "executeCall",
          "token": {
            "chainId": 1,
            "address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
            "name": "Ethereum",
            "symbol": "ETH",
            "decimals": 18,
            "logoURI": "https://assets.coingecko.com/coins/images/279/small/ethereum.png?1595348880",
            "coingeckoId": "ethereum"
          },
          "amount": "12439757116840000",
          "amountUSD": "15.0604",
          "gasPrice": "10117084325",
          "maxFeePerGas": "21447857098",
          "maxPriorityFeePerGas": "1500000000",
          "estimate": "580000",
          "limit": "667000"
        }
      ],
      "estimatedRouteDuration": 900,
      "exchangeRate": "93.72288569234398583",
      "aggregatePriceImpact": "0.51"
    },
    "params": {
      "slippage": 1,
      "toAddress": "0xC182aA0ecb24A674C00C76cE8F1761cC5a10611c",
      "fromAmount": "100000000000000000",
      "toToken": {
        "chainId": 43114,
        "address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
        "name": "Avalanche",
        "symbol": "AVAX",
        "decimals": 18,
        "logoURI": "https://raw.githubusercontent.com/pangolindex/tokens/main/assets/43114/0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7/logo_24.png",
        "coingeckoId": "avalanche-2"
      },
      "fromToken": {
        "chainId": 1,
        "address": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
        "name": "Ethereum",
        "symbol": "ETH",
        "decimals": 18,
        "logoURI": "https://assets.coingecko.com/coins/images/279/small/ethereum.png?1595348880",
        "coingeckoId": "ethereum"
      },
      "toChain": "43114",
      "fromChain": "1"
    },
    "transactionRequest": {
      "routeType": "CALL_BRIDGE_CALL",
      "targetAddress": "0xce16F69375520ab01377ce7B88f5BA8C48F8D666",
      "data": "0x8ca3bf680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016345785d8a000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000c182aa0ecb24a674c00c76ce8f1761cc5a10611c000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000094176616c616e6368650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000455534443000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000020000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000e47ff36ab500000000000000000000000000000000000000000000000000000000072a31bd0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000ce16f69375520ab01377ce7b88f5ba8c48f8d66600000000000000000000000000000000000000000000000000000184b55583850000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000320000000000000000000000000000000000000000000000000000000000000052000000000000000000000000000000000000000000000000000000000000006a000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000fab550568c688d5d8a52c7d794cb93edc26ec0ec0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000fab550568c688d5d8a52c7d794cb93edc26ec0ec000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000044095ea7b3000000000000000000000000890f4e345b1daed0367a877a1612f86a1f86985f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000fab550568c688d5d8a52c7d794cb93edc26ec0ec00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000890f4e345b1daed0367a877a1612f86a1f86985f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000c41a4c1ca3000000000000000000000000d7bb79aee866672419999a0496d99c54741d67b5000000000000000000000000fab550568c688d5d8a52c7d794cb93edc26ec0ec000000000000000000000000b97ef9ef8734c71904d8002f8b6bc66dd9c48a6e000000000000000000000000000000000000000000000000000000000732833f00000000000000000000000000000000000000000000000000000000073250a400000000000000000000000028d04fd16b2d7b8c0fdadb821e381b72fe3cc11e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000fab550568c688d5d8a52c7d794cb93edc26ec0ec00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001000000000000000000000000b97ef9ef8734c71904d8002f8b6bc66dd9c48a6e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000044095ea7b3000000000000000000000000e54ca86531e17ef3616d22ca28b0d458b6c891060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000b97ef9ef8734c71904d8002f8b6bc66dd9c48a6e00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000e54ca86531e17ef3616d22ca28b0d458b6c89106000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000104676528d100000000000000000000000000000000000000000000000000000000073428bf000000000000000000000000000000000000000000000000817abb51c523a81f00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000c182aa0ecb24a674c00c76ce8f1761cc5a10611c00000000000000000000000000000000000000000000000000000184b555838a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000b97ef9ef8734c71904d8002f8b6bc66dd9c48a6e000000000000000000000000b31f66aa3c1e785363f0875a1b74e27b85fd66c7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000b97ef9ef8734c71904d8002f8b6bc66dd9c48a6e0000000000000000000000000000000000000000000000000000000000000000",
      "value": "100503509582401222",
      "gasLimit": "667000",
      "gasPrice": "10117084325",
      "maxFeePerGas": "21447857098",
      "maxPriorityFeePerGas": "1500000000"
    }
  }
}

Note that the same token type (i.e. USDC) often has a different address on each chain. Make sure you've checked the address is right for the chain you are sending from/to.

Sending/receiving native tokens

If you want to send or receive native tokens (i.e ETH), the sourceTokenAddress or destinationTokenAddress arguments must be set to 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE

Executing your route

route.transactionRequest.targetAddress is the address of the smart contract to be called to execute the route

route.transactionRequest.data is the calldata to be executed at that address.

Please sign and submit the transaction in your preferred method. We recommend using our SDK for beginners in web3 EVM.

Last updated