exchangeAllForSui method
Exchange all WAL in a coin for SUI tokens.
Uses the first available exchange object from the package config.
The entire walCoinObjectId balance is exchanged.
Returns the transaction digest.
Mirrors the TS SDK's exchangeAllForSui contract call.
Implementation
Future<String> exchangeAllForSui({
required String walCoinObjectId,
required SuiAccount signer,
String? exchangeObjectId,
}) async {
final exchangeId = exchangeObjectId ?? _defaultExchangeId();
final txBuilder = await _ensureTxBuilder();
final exchangePkgId = await getWalExchangePackageId();
final tx = Transaction();
txBuilder.exchangeAllForSuiTransaction(
exchangeObjectId: exchangeId,
walCoinObjectId: walCoinObjectId,
walExchangePackageId: exchangePkgId,
transaction: tx,
);
tx.setSender(signer.getAddress());
final result = await suiClient.signAndExecuteTransactionBlock(
signer,
tx,
responseOptions: SuiTransactionBlockResponseOptions(showEffects: true),
);
return result.digest;
}