createBatchTransferTransaction method

Future<AptosRawTransaction> createBatchTransferTransaction({
  1. required AptosAddress sender,
  2. required List<AptosTransferParams> transfers,
  3. AptosApiBuildTransactionParams? params,
})

Creates a batch transfer transaction to send Aptos tokens to multiple recipients.

  • sender: The sender's address.
  • transfers: A list of transfer parameters for each recipient.
  • params (optional): Additional transaction settings.

Throws an exception if any account is inactive and allowCreate is set to false.

Implementation

Future<AptosRawTransaction> createBatchTransferTransaction({
  required AptosAddress sender,
  required List<AptosTransferParams> transfers,
  AptosApiBuildTransactionParams? params,
}) async {
  if (transfers.isEmpty) {
    throw DartAptosPluginException("At least one transfer required.");
  }

  for (final transfer in transfers) {
    if (!transfer.allowCreate &&
        !await accountIsActive(transfer.destination)) {
      throw DartAptosPluginException(
        "Account is not active.",
        details: {"address": transfer.destination.toString()},
      );
    }
  }

  final transactionPayload = AptosTransactionPayloadEntryFunction(
      entryFunction: AptosHelper.createBatchTransferTransferEntry(transfers));

  return buildTransaction(
      sender: sender, transactionPayload: transactionPayload, params: params);
}