exchangeForWalTransaction method

dynamic exchangeForWalTransaction({
  1. required String exchangeObjectId,
  2. required String suiCoinObjectId,
  3. required BigInt amountSui,
  4. required String walExchangePackageId,
  5. Transaction? transaction,
})

Build a transaction that exchanges a specific amount of SUI for WAL.

Calls wal_exchange::wal_exchange::exchange_for_wal on the exchange object. Splits amountSui from suiCoinObjectId and exchanges it.

Returns the resulting WAL coin transaction result.

Mirrors the TS SDK's WAL exchange contract exchangeForWal.

Implementation

dynamic exchangeForWalTransaction({
  required String exchangeObjectId,
  required String suiCoinObjectId,
  required BigInt amountSui,
  required String walExchangePackageId,
  Transaction? transaction,
}) {
  final tx = transaction ?? Transaction();

  final suiCoin = tx.object(suiCoinObjectId);
  final result = tx.moveCall(
    '$walExchangePackageId::wal_exchange::exchange_for_wal',
    arguments: [
      tx.object(exchangeObjectId), // self: &mut Exchange
      suiCoin, // sui: &mut Coin<SUI>
      tx.pure.u64(amountSui), // amount_sui: u64
    ],
  );

  return result;
}