exchangeForSui method
Exchange a specific amount of WAL for SUI tokens.
Uses the first available exchange object from the package config.
The walCoinObjectId must have at least amountWal balance.
Returns the transaction digest.
Mirrors the TS SDK's exchangeForSui contract call.
Implementation
Future<String> exchangeForSui({
required String walCoinObjectId,
required BigInt amountWal,
required SuiAccount signer,
String? exchangeObjectId,
}) async {
final exchangeId = exchangeObjectId ?? _defaultExchangeId();
final txBuilder = await _ensureTxBuilder();
final exchangePkgId = await getWalExchangePackageId();
final tx = Transaction();
txBuilder.exchangeForSuiTransaction(
exchangeObjectId: exchangeId,
walCoinObjectId: walCoinObjectId,
amountWal: amountWal,
walExchangePackageId: exchangePkgId,
transaction: tx,
);
tx.setSender(signer.getAddress());
final result = await suiClient.signAndExecuteTransactionBlock(
signer,
tx,
responseOptions: SuiTransactionBlockResponseOptions(showEffects: true),
);
return result.digest;
}