๐Ÿ”ƒ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

Request routing for the specified tokens and networks

Copy

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

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

Copy

3. Forming data for sending the transaction

Copy

4. Sending the transaction

Copy

Last updated