Get a route
// Set up parameters for swapping tokens and depositing into Radiant lending pool
const params = {
  fromAddress: signer.address,
  fromChain: arbitrumId,
  fromToken: usdcArbitrumAddress,
  fromAmount: amount,
  toChain: polygonId,
  toToken: nativeToken,
  toAddress: signer.address,
  slippage: 1,
  quoteOnly: false,
};
// Get the swap route using Squid SDK
const { route, requestId } = await squid!.getRoute(params);
You can then explore the route response. This includes all the information on your quote route.estimate and all the data needed to generate a transaction route.transactionRequest.
// Function to get the optimal route for the swap using Squid API
const getRoute = async (params: any) => {
  try {
    const result = await axios.post(
      "https://apiplus.squidrouter.com/v2/route",
      params,
      {
        headers: {
          "x-integrator-id": integratorId,
          "Content-Type": "application/json",
        },
      }
    );
    const requestId = result.headers["x-request-id"]; // Retrieve request ID from response headers
    return { data: result.data, requestId: requestId };
  } catch (error) {
    if (error.response) {
      console.error("API error:", error.response.data);
    }
    console.error("Error with parameters:", params);
    throw error;
  }
};
// Get the swap route using Squid API
const routeResult = await getRoute(params);
const route = routeResult.data.route;
const requestId = routeResult.requestId;
console.log("Calculated route:", route);
console.log("requestId:", requestId);All Squid widgets will get a route when the user can entered all the necessary parameters.
Widgets refresh quotes every 20 seconds.
Last updated