Class BatchTransaction


public final class BatchTransaction extends Transaction<BatchTransaction>
Execute multiple transactions in a single consensus event. This allows for atomic execution of multiple transactions, where they either all succeed or all fail together.

Requirements:

  • All inner transactions must be frozen before being added to the batch
  • All inner transactions must have a batch key set
  • All inner transactions must be signed as required for each individual transaction
  • The BatchTransaction must be signed by all batch keys of the inner transactions
  • Certain transaction types (FreezeTransaction, BatchTransaction) are not allowed in a batch

Important notes:

  • Fees are assessed for each inner transaction separately
  • The maximum number of inner transactions in a batch is limited to 25
  • Inner transactions cannot be scheduled transactions

Example usage:

 var batchKey = PrivateKey.generateED25519();

 // Create and prepare inner transaction
 var transaction = new TransferTransaction()
     .addHbarTransfer(sender, amount.negated())
     .addHbarTransfer(receiver, amount)
     .batchify(client, batchKey);

 // Create and execute batch transaction
 var response = new BatchTransaction()
     .addInnerTransaction(transaction)
     .freezeWith(client)
     .sign(batchKey)
     .execute(client);