Requesting a Quote

Once you've gathered the transaction information, the next step is to obtain a possible route from the Swing API. The route information contains the fees and total amount that a wallet holder will have to pay for the transaction to be processed by Swing.

The full API reference for our /quote endpoint can be found in the API reference section.

Making a Request

URL: https://swap.prod.swing.xyz/v0/transfer/quote

Query Parameters:

PropertyExampleDescription
tokenAmount1000000000000000000Amount of the source token being sent (in wei for ETH).
fromChainethereumSource Chain slug
fromUserAddress0x018c15DA1239B84b08283799B89045CD476BBbBbSender's wallet address
fromTokenAddress0x0000000000000000000000000000000000000000Source Token Address
tokenSymbolETHSource Token slug
toTokenAddress0x0000000000000000000000000000000000000000Destination Token Address.
toTokenSymbolMATICDestination Token slug
toChainpolygonDestination Chain slug
toUserAddress0x018c15DA1239B84b08283799B89045CD476BBbBbReceiver's wallet address
projectIdreplugYour project's ID
contractCallfalseReturn only contract-call enabled routes

Sample Request

const result = await axios.post(
  'https://swap.prod.swing.xyz/v0/transfer/quote',
  {
    fromChain: 'polygon',
    tokenSymbol: 'USDC',
    fromTokenAddress: '0xcbe56b00d173a26a5978ce90db2e33622fd95a28',
    fromUserAddress: '0x018c15DA1239B84b08283799B89045CD476BBbBb',
    toChain: 'ethereum',
    toTokenSymbol: 'ETH',
    toTokenAddress: '0x0000000000000000000000000000000000000000',
    toUserAddress: '0x018c15DA1239B84b08283799B89045CD476BBbBb',
    tokenAmount: '1000000000',
    projectId: 'replug',
  },
);

Sample Response

{
  "routes": [
    {
      "duration": 21,
      "gas": "79763766680877486",
      "quote": {
        "integration": "stargate",
        "type": "swap",
        "bridgeFee": "335944783370",
        "bridgeFeeInNativeToken": "126544791628329747946",
        "amount": "317170992781854",
        "decimals": 18,
        "amountUSD": "0.970",
        "bridgeFeeUSD": "0.00103",
        "bridgeFeeInNativeTokenUSD": "84.540",
        "fees": [
          {
            "type": "bridge",
            "amount": "335944783370",
            "amountUSD": "0.00103",
            "chainSlug": "ethereum",
            "tokenSymbol": "ETH",
            "tokenAddress": "0x0000000000000000000000000000000000000000",
            "decimals": 18,
            "deductedFromSourceToken": true
          }
        ]
      },
      "route": [
        {
          "bridge": "stargate",
          "bridgeTokenAddress": "0xc2132d05d31c914a87c6611c10748aeb04b58e8f",
          "steps": ["allowance", "approve", "send"],
          "name": "USDT",
          "part": 100
        }
      ],
      "distribution": {
        "stargate": 1
      },
      "gasUSD": "0.05329"
    }
  ],
  "fromToken": {
    ...
  },
  "fromChain": {
    ...
  },
  "toToken": {
    ...
  },
  "toChain": {
    ...
  }
}

Request a Contract Call Quote

When executing a contract call, you need to ensure that the routes/integrations being returned from the /quote endpoint supports contract calls.

To return only contract call enabled routes from the /qoute endpoint, set the contractCall parameter to true:

Sample Request

const result = await axios.post(
  'https://swap.prod.swing.xyz/v0/transfer/quote',
  {
    fromChain: 'polygon',
    tokenSymbol: 'USDC',
    fromTokenAddress: '0xcbe56b00d173a26a5978ce90db2e33622fd95a28',
    fromUserAddress: '0x018c15DA1239B84b08283799B89045CD476BBbBb',
    toChain: 'ethereum',
    toTokenSymbol: 'ETH',
    toTokenAddress: '0x0000000000000000000000000000000000000000',
    toUserAddress: '0x018c15DA1239B84b08283799B89045CD476BBbBb',
    tokenAmount: '1000000000',
    projectId: 'replug',
    contractCall: true, // set this parameter to true
  },
);