# Build Swap Transaction

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

<mark style="color:blue;">`GET`</mark> `endpoint/swap`

Parameters

#### Query Parameters

| Name                                               | Type   | Description                                                                                                                                                                              |
| -------------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| srcChainId<mark style="color:red;">\*</mark>       | String | ID of source chain                                                                                                                                                                       |
| fromTokenAddress<mark style="color:red;">\*</mark> | String | Token to be swapped from source chain                                                                                                                                                    |
| amount<mark style="color:red;">\*</mark>           | 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<mark style="color:red;">\*</mark>      | String | ID of target chain                                                                                                                                                                       |
| toTokenAddress<mark style="color:red;">\*</mark>   | String | Token to be received on target chain                                                                                                                                                     |
| receiveAddress<mark style="color:red;">\*</mark>   | 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                                                                                   |

{% tabs %}
{% tab title="200: OK Success" %}

```javascript
{
  "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
}
```

{% endtab %}

{% tab title="200: OK No routes available" %}

```javascript
{
    "isSuccess": false,
    "msg": "Token unsupported or liquidity insufficient."
    "statusCode": "3",
    "destChainId": "<target chain ID>",
    "fromTokenAddress": "<address>",
    "toTokenAddress": "<address>",
    "fromTokenAmount": "<amount>",
    "contractAddress": null,
    "srcChainId": "<source chain ID>",
    "toTokenAmount": "0",
    "xyFee": null,
}
```

{% endtab %}

{% tab title="200: OK Bridge liquidity not enough" %}

```javascript
{
    "isSuccess": false,
    "msg": "yBridge liquidity insufficient."
    "statusCode": "4",
    "destChainId": "<target chain ID>",
    "fromTokenAddress": "<address>",
    "toTokenAddress": "<address>",
    "fromTokenAmount": "<amount>",
    "contractAddress": null,
    "srcChainId": "<source chain ID>",
    "toTokenAmount": "0",
    "xyFee": null,
}
```

{% endtab %}

{% tab title="200: OK Swap amount not enough" %}

```javascript
{
    "isSuccess": false,
    "msg": "The minimum swap amount for this trading pair should be equivalent to {min_amount} {token_symbol}."
    "statusCode": "6",
    "destChainId": "<target chain ID>",
    "fromTokenAddress": "<address>",
    "toTokenAddress": "<address>",
    "fromTokenAmount": "<amount>",
    "contractAddress": null,
    "srcChainId": "<source chain ID>",
    "toTokenAmount": "0",
    "xyFee": null,
}
```

{% endtab %}

{% tab title="200: OK Route engine temporary timeout" %}

```javascript
{
    "isSuccess": false,
    "msg": "Request for route-fetching has timed out. Please try again."
    "statusCode": "5",
    "destChainId": "<target chain ID>",
    "fromTokenAddress": "<address>",
    "toTokenAddress": "<address>",
    "fromTokenAmount": "<amount>",
    "contractAddress": null,
    "srcChainId": "<source chain ID>",
    "toTokenAmount": "0",
    "xyFee": null,
}
```

{% endtab %}
{% endtabs %}

### 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&#x20;
* 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](https://docs.xy.finance/single-bridge-integration/ybridge-api/supported-blockchains "mention") to get latest list

### Example Request

```shell
$ 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**.
