exchangeAllForWal method

Future<String> exchangeAllForWal({
  1. required String suiCoinObjectId,
  2. required SuiAccount signer,
  3. String? exchangeObjectId,
})

Exchange all SUI in a coin for WAL tokens.

Uses the first available exchange object from the package config. The entire suiCoinObjectId balance is exchanged.

Returns the transaction digest.

Mirrors the TS SDK's exchangeAllForWal contract call.

Implementation

Future<String> exchangeAllForWal({
  required String suiCoinObjectId,
  required SuiAccount signer,
  String? exchangeObjectId,
}) async {
  final exchangeId = exchangeObjectId ?? _defaultExchangeId();
  final txBuilder = await _ensureTxBuilder();
  final exchangePkgId = await getWalExchangePackageId();

  final tx = Transaction();
  final coin = txBuilder.exchangeAllForWalTransaction(
    exchangeObjectId: exchangeId,
    suiCoinObjectId: suiCoinObjectId,
    walExchangePackageId: exchangePkgId,
    transaction: tx,
  );
  tx.transferObjects([coin], signer.getAddress());
  tx.setSender(signer.getAddress());

  final result = await _executeTransaction(
    signer,
    tx,
    responseOptions: SuiTransactionBlockResponseOptions(showEffects: true),
  );

  return result.digest;
}