4️⃣Build Swap Transaction

Returns the swap data for bridging tokens

This API returns the details about the quote and the transaction that will trigger a single-chain or cross-chain swap request according to the quotation.

Get the swap transaction from the quote

GET endpoint/swap

Parameters

Query Parameters

Name
Type
Description

srcChainId*

String

ID of source chain

fromTokenAddress*

String

Token to be swapped from source chain

amount*

String

Amount of tokens to be swapped and please consider the decimal and pad with zeroes for the amount. For example, pass 100000000 instead of 100 if the token has 6 decimal digits.

destChainId*

String

ID of target chain

toTokenAddress*

String

Token to be received on target chain

receiveAddress*

String

Receiver of the swapped token on target chain

slippage

String

Percentage of slippage tolerance ex: 1% you need to input 1 in the field

referrer

String

Address of the referrer, this address will be used uniformly for any future partner incentive programs

{
  "isSuccess": true,
  "msg": "Swap success.",
  "statusCode": "0",
  "destChainId": "137",
  "fromTokenAddress": "0xdac17f958d2ee523a2206206994597c13d831ec7",
  "toTokenAddress": "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",
  "fromTokenAmount": "1000000000",
  "toTokenAmount": "512870365878922641408",
  "fromTokenValue": 199.5,
  "toTokenValue": 198,
  "srcChainId": "1",
  "receiveAddress": "0x351B18b4f84CBCc700F4e30a15854745F400f08b",
  "minimumReceived": "46.5370365878922641408",
  "crossChainFee": {},
  "estimatedGas": 300000,
  "xyFee": {
    "amount": 1.2,
    "symbol": "USDT"
  },
  "quote": {
    "sourceChainSwaps": null,
    "crossChainSwap": {
      "dexNames": [
        "yBridge"
      ],
      "fromToken": {
        "tokenAddress": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
        "chainId": "1",
        "symbol": "USDT",
        "decimals": 6
      },
      "toToken": {
        "tokenAddress": "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
        "chainId": "137",
        "symbol": "USDT",
        "decimals": 6
      }
    },
    "destChainSwaps": {
      "dexNames": [
        "SushiSwap"
      ],
      "fromToken": {
        "tokenAddress": "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
        "chainId": "137",
        "symbol": "USDT",
        "decimals": 6
      },
      "toToken": {
        "tokenAddress": "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
        "chainId": "137",
        "symbol": "WMATIC",
        "decimals": 18
      }
    },
    "toTokenAmount": "512.8703658789226"
  },
  "tx": {
    "to": "0x73Ce60416035B8D7019f6399778c14ccf5C9c7A1",
    "data": "0x3fc8ef10000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000351b18b4f84cbcc700f4e30a15854745f400f08b000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000890000000000000000000000000d500b1d8e8ef31e21c99d1db9a6444d3adf127000000000000000000000000000000000000000000000001bcd81907695ce0000000000000000000000000000000000000000000000000000000000000000003200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000",
    "value": 0
  },
  "estimatedTransferTime": 270,
  "transactionCounts": 2
}

Parameter/Response Details

  • Use 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE as the address for the native token in your parameter.

  • Note that the amount parameter should be padded with zeroes. For example, pass 100000000 instead of 100 if the decimal digits of the token are 6.

  • Before submitting a transaction, please make sure that the chain you are on and the selected srcChainId are the same, to avoid sending the transaction to an unknown contract address

  • The destChainId must be one of the chains supported by yBridge. If your destChainId is not supported by yBridge, the funds may be temporarily locked in the system. you could use Supported Blockchains to get latest list

Example Request

$ curl https://open-api.xy.finance/v1/swap?srcChainId=1&fromTokenAddress=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee&amount=500000000000000000&destChainId=56&toTokenAddress=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee&slippage=1&referrer=0x8c6bDCb8c66fe5BFAa82510413665833FCFa08Ee&receiveAddress=0xbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef

This request is for a quote of 0.5 ETH on Ethereum to BNB on BNB Chain, with a 1% slippage and a referrer of 0x8c6bDCb8c66fe5BFAa82510413665833FCFa08Ee. The asset on the target chain will be eventually sent to 0xbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef.

Last updated

Was this helpful?