Swap

If you want to swap tokens on the same chain

// initiate transfer
const swapParams: SwapParams = {
  amount: amount,
  fromAccountAddress: fromAddress,
  toAccountAddress: toAddress,
  sourceToken: sourceTokenInfo,
  destinationToken: destinationTokenInfo,
  minimumReceiveAmount: await sdk.getAmountToBeReceived(amount, sourceTokenInfo, destinationTokenInfo),
};
const rawTransactionTransfer = await sdk.bridge.rawTxBuilder.send(swapParams) as RawEvmTransaction;

console.log(`Swaping ${amount} ${sourceTokenInfo.symbol}`);
const txReceipt = await sendRawTransaction(rawTransactionTransfer);
console.log("tx id:", txReceipt.transactionHash);

Full example

Last updated