Butter Network
Github
  • 🌈About Butter Network
  • 🔥ZK Light Client
    • Understanding Light Client
    • Refactored ZK Light Client
  • 🔥Omnichain Development
    • Omnichain Isomorphism
    • More Possibilities
  • 🌈Butter Omnichain Messaging Integration
    • Introduction
    • Integration Guide
      • Message
      • Message with Ton
      • CALLDATA
      • Message And Relay
    • Contract Interface
    • Fee
    • Deployed Contracts
    • 👨‍💻API for Omnichain Message
      • GET Message History by Source Address
      • GET Message Info by Id
      • GET Message Info by Source Hash
  • 🔥Butter Bridge Integration
    • Integration Guide
    • Contract Interface
    • Fee
    • Deployed Contracts
  • 💰Butter Swap Integration
    • Introduction
    • 🟢Integration Guide
      • Contract Interface
      • Fee
    • Deployed Contracts
      • v2.1
    • 👩‍💻API for Routing
      • Integration Guide
      • GET /route
      • GET /swap
      • GET /routeAndSwap
      • GET /supportedChainList
      • GET /findToken
      • 🔴Error Code List
    • 👨‍💻API for Swap Data
      • GET Swap History by Source Hash
      • GET Swap History by Source Address
      • GET Swap Info by Order ID
      • GET Supported Chain Detail List
      • GET Supported Token Detail List
  • 💰Butter Swap User Guide
    • 🫂User Guide
  • Butter Swap SDK
    • Install
    • Config SDK
    • Request Routes
    • Execute Route
    • Others
  • Butter Swap Widget
    • Usage
  • 📢Resources
    • 🏠Website
    • 🫂Telegram
    • 📄X
Powered by GitBook
On this page
  • How to
  • Routes request parameters
  • Response
  1. Butter Swap SDK

Request Routes

To executing any swap or bridging, you need to request the best route from our smart routing API.

The Butter SDK provides functionality to request routes and quotes, as well as to execute them. This guide will walk you through the process of making a request using getRoutes function.

How to

Here is a example to request a route to bridge 1000 MAPO from Map protocol to Binance Smart Chain.

import { getRoutes } from "@butternetwork/sdk";

const routes = await getRoutes({
  fromChainId: "22776",
  toChainId: "56",
  amount: "1000",
  tokenInAddress: "0x0000000000000000000000000000000000000000",
  tokenOutAddress: "0x55d398326f99059ff775485246999027b3197955",
  type: "exactIn",
  slippage: "200",
  entrance: "Butter+",
});

When you request routes, you receive an array of route objects containing the essential information to determine which route to take for a swap or bridging transfer. At this stage, transaction data is not included and must be requested separately. Read more Execute Routes/Quotes.

Routes request parameters

Below are the parameters for the RoutesRequest interface along with their descriptions:

fromChainId (string, required)

The Chain Id of the source chain.

toChainId (string, required) The Chain Id of the destination chain.

amount (string, required) The amount of tokens to be swapped or bridged.

tokenInAddress (string, required) The address of the token to be swapped or bridged.

tokenOutAddress (string, required) The address of the token to be received.

type (string, required) The type of swap or bridging. Possible values are exactIn and exactOut.

slippage (string, required) The slippage tolerance percentage.

entrance (string, required) The entrance of the swap or bridging. Default value is Butter+.

abortSignal (AbortSignal, optional) The signal to abort the request.

Response

The response is an array of route objects. Each route object contains the following fields:

export interface Route {
  // The difference between current route and the best route
  diff: string;
  bridgeFee: {
    amount: string;
    symbol: string;
  };
  // 0 for exactIn / 1 for exactOut
  tradeType: number;
  gasFee: {
    amount: string;
    symbol: string;
  };
  gasEstimated: string;
  // hash for reqeust route tx
  hash: string;
  srcChain: ChainInRoute;
  bridgeChain: ChainInRoute;
  dstChain: ChainInRoute;
  minAmountOut: {
    amount: string;
    symbol: string;
  };
  timeEstimated: number;
}
PreviousConfig SDKNextExecute Route

Last updated 4 months ago