Rubic Documents
Search…
⌃K
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(...);
const bestTrade = trades[0] instanceof InstantTrade && trades[0];
const receipt = await bestTrade.swap();

Cross-Chain trade example

const trade = await sdk.crossChain.calculateTrade(tradeParams);
const bestTrade = trades[0].trade.swap();
const transactionHash = await bestTrade.swap();
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.