4️⃣Swap Execution
Before swap, you should calculate a trade object
On-Chain trade example
const trades = await sdk.onChainManager.calculateTrade(...);
const bestTrade = trades[0] instanceof OnChainTrade && 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();Swap 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;
/**
* Tokens receiver address.
*/
receiverAddress?: string;
/**
* Transaction gas price options.
*/
gasPriceOptions?: EIP1559Gas | SingleGasPrice;
/**
* Approve transaction gas limit.
* Will be used for approve transaction, if it is called before swap.
*/
approveGasLimit?: string;
/**
* Approve tron-transaction fee limit.
* Will be used for approve transaction, if it is called before swap.
*/
approveFeeLimit?: number;
}
Last updated