4⃣
Swap perform
Before swap, you should calculate a trade object
Swap for both On-Chain and Cross-Chain trade are pretty similar and very easy to use. You just have to call swap method in trade object (instantTrade or crossChain).

On-Chain trade example

const trades = await sdk.instantTrades.calculateTrade(tradeParams);
const receipt = await trades[TRADE_TYPE.UNISWAP_V2].swap(swapOptions);

Cross-Chain trade example

const trade = await sdk.crossChain.calculateTrade(tradeParams);
const transactionHash = await trade.swap(swapOptions);
After swap execution you will get the transaction receipt or hash in case of cross-chain swap.
Well done!

Swap options

Swap method takes optional params with options:
interface SwapOptions {
/**
* Callback to be called, when user confirm swap transaction.
* @param hash Transaction hash.
*/
onConfirm?: (hash: string) => void;
/**
* Callback to be called, when user confirm approve transaction.
* @param hash Transaction hash.
*/
onApprove?: (hash: string | null) => void;
/**
* Transaction gas price.
*/
gasPrice?: string;
/**
* Swap transaction gas limit.
*/
gasLimit?: string;
/**
* Approve transaction gas limit.
* Will be used for approve transaction, if it is called before swap.
*/
approveGasLimit?: string;
}
With these parameters, you can specify your gas data or actions which will be executed right after transaction signing.
Copy link
Outline