> For the complete documentation index, see [llms.txt](https://docs.crosscurve.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.crosscurve.fi/developer-documentation/guide-for-developers/make-cross-chain-swap.md).

# Make cross-chain swap

Performing a cross-chain swap consists of 4 steps:

1. Routing construction
2. Estimating cross-chain operations
3. Forming data for the transaction
4. Sending the transaction

### 1. Routing construction <a href="#id-1.-routing-construction" id="id-1.-routing-construction"></a>

Request routing for the specified tokens and networks

Copy

```solidity
const requestRoutingParams = {
    params: {
         chainIdIn": 1, // Ethereum
         chainIdOut: 250, // Fantom
         tokenIn: "0xdac17f958d2ee523a2206206994597c13d831ec7", // USDT
         tokenOut: "0xe71286fc887189c562410af12ed521c8e58e5fa3", // s3crypto_e
         amountIn: "100000000", // 100 USDT
    },
    slippage: 1, // 1%
}

const response = await fetch('https://api.crosscurve.fi/routing/scan', {
    method: 'POST',
    body: JSON.stringify(requestRoutingParams),
    headers: {
        "Content-Type": "application/json",
    },
})

const routing = await response.json()
```

### 2. Making a route estimate <a href="#id-2.-making-a-route-estimate" id="id-2.-making-a-route-estimate"></a>

From the obtained array of routes, take the first route (which is the most profitable for swapping) and send it for estimation

Copy

```solidity
const bestRoute = routing[0]

const response = await fetch('https://api.crosscurve.fi/estimate', {
    method: 'POST',
    body: JSON.stringify(bestRoute),
    headers: {
        "Content-Type": "application/json",
    },
})

const estimate = await response.json()
```

### 3. Forming data for sending the transaction <a href="#id-3.-forming-data-for-sending-the-transaction" id="id-3.-forming-data-for-sending-the-transaction"></a>

Copy

```solidity
const txCreateParams = {
    from: '0x...', // sender
    recipient: '0x...', // recipient
    routing,
    estimate,
}

const response = await fetch('https://api.crosscurve.fi/tx/create', {
    method: 'POST',
    body: JSON.stringify(txCreateParams),
    headers: {
        "Content-Type": "application/json",
    },
})

const rawTx = await response.json()
```

### 4. Sending the transaction <a href="#id-4.-sending-the-transaction" id="id-4.-sending-the-transaction"></a>

Copy

```solidity
import { Contract, JsonRpcProvider } from 'ethers'
 
const provider = new JsonRpcProvider('RPC_URL_HERE')
const signer = new Wallet(process.env.PRIVATE_KEY, provider)

const router = new Contract(rawTx.to, [rawTx.abi], signer)

const args = [
  rawTx.args[0],
  rawTx.args[1],
  [
    rawTx.args[2].executionPrice,
    rawTx.args[2].deadline,
    rawTx.args[2].v,
    rawTx.args[2].r,
    rawTx.args[2].s,
  ],
]

const value = BigInt(rawTx.value) + BigInt(estimate.executionPrice)

const tx = await router.start(...args, { value })
const receipt = await tx.wait()
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.crosscurve.fi/developer-documentation/guide-for-developers/make-cross-chain-swap.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
