exchangeAllForWal method
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();
txBuilder.exchangeAllForWalTransaction(
exchangeObjectId: exchangeId,
suiCoinObjectId: suiCoinObjectId,
walExchangePackageId: exchangePkgId,
transaction: tx,
);
tx.setSender(signer.getAddress());
final result = await suiClient.signAndExecuteTransactionBlock(
signer,
tx,
responseOptions: SuiTransactionBlockResponseOptions(showEffects: true),
);
return result.digest;
}