Step 2: Get a contract-call quote

Retrieving a valid quote from contract-call-supported routes.

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

This is the first prerequisite step for any transaction on the Swing API. We want to determine which route provides us with the best quote based on our needs.

Our quoting system requires all the following required information:

  • Source chain
  • Destination chain
  • Source Token on the Source chain
  • Destination Token on the Destination chain
  • The amount you want to send
  • Contract Call flag
  • Source Wallet Address to pull funds from

We can query our /quote endpoint in the following manner given all the necessary information:

const getQuote = async () => {
  const result = await axios.get(
    'https://swap.prod.swing.xyz/v0/transfer/quote',
    {
      //source chain parameters
      fromChain: 'polygon',
      tokenSymbol: 'USDC',
      fromTokenAddress: '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359',
 
      //destination chain parameters
      toChain: 'ethereum',
      toTokenSymbol: 'ETH',
      toTokenAddress: '0x0000000000000000000000000000000000000000',
 
      //transfer parameters
      fromUserAddress: '0x018c15DA1239B84b08283799B89045CD476BBbBb',
      tokenAmount: '1000000000',
      contractCall: true,
    },
  );
  return result.data;
};

The results for our quote will include the routes property which will have all the possible routes that can support the requested transaction. Each route also includes the fees associated with that route learn more about fees.

The results for our quote will look like this for a cross-chain transaction:

{
  "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
          },
          {
            "type": "bridge",
            "amount": "126544791628329747946",
            "amountUSD": "84.540",
            "chainSlug": "polygon",
            "tokenSymbol": "MATIC",
            "tokenAddress": "0x0000000000000000000000000000000000000000",
            "decimals": 18,
            "deductedFromSourceToken": false
          },
          {
            "type": "gas",
            "amount": "79763766680877486",
            "amountUSD": "0.05329",
            "chainSlug": "polygon",
            "tokenSymbol": "MATIC",
            "tokenAddress": "0x0000000000000000000000000000000000000000",
            "decimals": 18,
            "deductedFromSourceToken": false
          },
          {
            "type": "partner",
            "amount": "0",
            "amountUSD": "0",
            "chainSlug": "polygon",
            "tokenSymbol": "USDC",
            "tokenAddress": "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359",
            "decimals": 6,
            "deductedFromSourceToken": true
          }
        ]
      },
      "route": [
        {
          "bridge": "stargate",
          "bridgeTokenAddress": "0xc2132d05d31c914a87c6611c10748aeb04b58e8f",
          "steps": ["allowance", "approve", "send"],
          "name": "USDT",
          "part": 100
        }
      ],
      "distribution": {
        "stargate": 1
      },
      "gasUSD": "0.05329"
    }
  ],
  "fromToken": {
    "address": "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359",
    "symbol": "USDC",
    "name": "USDC",
    "decimals": 6,
    "logoURI": "https://raw.githubusercontent.com/multiversx/mx-assets/master/tokens/USDC-c76f1f/logo.png"
  },
  "fromChain": {
    "chainId": 137,
    "name": "Polygon",
    "slug": "polygon",
    "protocolType": "evm"
  },
  "toToken": {
    "address": "0x0000000000000000000000000000000000000000",
    "symbol": "ETH",
    "name": "ETH",
    "decimals": 18,
    "logoURI": "https://raw.githubusercontent.com/polkaswitch/assets/master/blockchains/solana/assets/7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs/eth.jpg"
  },
  "toChain": {
    "chainId": 1,
    "name": "Ethereum",
    "slug": "ethereum",
    "protocolType": "evm"
  }
}