Swap

Swap makes the same way as a transfer, but you have to specify tokens from the one chain

// initiate transfer using Messenger.WORMHOLE
const amount = "10";
const transaction = (await sdk.bridge.rawTxBuilder.send({
  amount: amount,
  fromAccountAddress: accountAddress,
  toAccountAddress: accountAddress,
  sourceToken: sourceTokenInfo,
  destinationToken: destinationTokenInfo,
  minimumReceiveAmount: await sdk.getAmountToBeReceived(amount, sourceTokenInfo, destinationTokenInfo),
})) as RawSolanaTransaction;

const keypair = solanaWeb3.Keypair.fromSecretKey(bs58.decode(privateKey));
transaction.sign([keypair]);

const connection = new solanaWeb3.Connection(nodeUrlsDefault.solanaRpcUrl, "confirmed");
const txId = await connection.sendTransaction(transaction);
console.log(`https://explorer.solana.com/tx/${txId}`);

Full example

Last updated