exchangeForWal method

Future<String> exchangeForWal({
  1. required String suiCoinObjectId,
  2. required BigInt amountSui,
  3. required SuiAccount signer,
  4. String? exchangeObjectId,
})

Exchange a specific amount of SUI for WAL tokens.

Uses the first available exchange object from the package config. The suiCoinObjectId must have at least amountSui balance.

Returns the transaction digest.

Mirrors the TS SDK's exchangeForWal contract call.

Implementation

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

  final tx = Transaction();
  txBuilder.exchangeForWalTransaction(
    exchangeObjectId: exchangeId,
    suiCoinObjectId: suiCoinObjectId,
    amountSui: amountSui,
    walExchangePackageId: exchangePkgId,
    transaction: tx,
  );
  tx.setSender(signer.getAddress());

  final result = await suiClient.signAndExecuteTransactionBlock(
    signer,
    tx,
    responseOptions: SuiTransactionBlockResponseOptions(showEffects: true),
  );

  return result.digest;
}