# Swaps

Crosschain swap is the exchange of one asset for another.

To carry out an asset swap, you need to make sure that this service is available in the networks you have chosen. To do this, request [list of available coins](#e4658fd5-5daf-4689-b845-663f8ed93470), find the coin you need, it will have a list of `networks` networks, make sure that the network of the asset you want to swap the `allowCrosschainSwapFrom` flag is wound `true`, and the network of the asset you want to receive has `allowCrosschainSwapTo` equal to `true`.

For example:\
You have **ETH** in the **Ethereum** network, in the list of available coins you should find the **ETH** coin, then in the list of `networks` find the `ethereum` network it should have `"allowCrosschainSwapFrom ": true`

```json
{
  "success": true,
  "response": [
    ...
    {
      "currency": "ETH",
      ...
      "networks": [
        ...
        {
          "name": "ethereum",
          ...
          "allowCrosschainSwapFrom": true,
          ...
        }
        ...
      ]
    },
    ...
  ]
}

```

You want to swap it for **USDT** on the **Tron** network, in the list of available coins you should find the **USDT** coin, then in the `networks` list, find the `tron` network, it should have `"allowCrosschainSwapTo": true`

```json
{
  "success": true,
  "response": [
    ...
    {
      "currency": "USDT",
      ...
      "networks": [
        ...
        {
          "name": "tron",
          ...
          "allowCrosschainSwapTo": true,
          ...
        }
        ...
      ]
    },
    ...
  ]
}

```

Find out the [allowable limit](#ebafca69-7149-4387-824d-3af906b37628) for the transaction amount. Please note that the limit amounts are indicated in **USD**, the rates of such stablecoins as **USDT**, **BUSD** etc do not differ significantly from the rate of **USD**, and if you want to exchange another coin, then you will need to get the exchange rate to **USD** to make sure that your amount meets the specified limits.

Request [fee preview](#1eb19a91-5101-4113-9bbd-e8b91467e181) to get a `token`, it will need to be specified when [requesting transaction creation](#75929dd7-c7f5-44b7-b830-018c2e0a0efe) as `feeToken`.

The operation is not executed immediately after the request, you must wait 1-3 minutes. You can [find out the operation execution status](#f1272a4a-fa54-4bb9-b627-43eafb81a6b8) yourself, or you can specify the URL to receive the [webhook](#webhooks) in the `webhookUrl` field when creating.

Available statuses

| **Status** | **Description**        |
| ---------- | ---------------------- |
| CREATED    | Request registered     |
| PENDING    | Processing             |
| ERROR      | Error during execution |
| REJECTED   | Request rejected       |
| PROCESSED  | Success                |

## API Interaction Scheme

{% @mermaid/diagram content="sequenceDiagram
Merchant ->> Onchainpay: Request fee token
Onchainpay ->> Merchant: Fee token
Merchant ->> Onchainpay: Creating operation
Onchainpay ->> Merchant: Operation body

```
Note over Onchainpay: Processing operation

Onchainpay -->> Merchant: Operation result webhook" %}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.onchainpay.io/api-reference/09crosschain_swaps.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
