executeBatch method

Future<String> executeBatch(
  1. String currentAddress,
  2. bool? useDefaultPaymaster
)

Executes a batch of Ethereum transactions and returns the user operation hash.

This function executes a batch of Ethereum transactions by generating a user operation, signing it, and sending it to the Ethereum network.

Parameters:

  • currentAddress(optional): Current connected wallet address of the user initiating the batch execution (When signed in using metaamask/openlogin or any other wallet).
  • useDefaultPaymaster(optional): A boolean indicating whether to use the default paymaster for gas payment. Overrides the default value of usePaymaster in the current instance.

Returns:

  • A Future

Implementation

Future<String> executeBatch(
  String currentAddress,
  bool? useDefaultPaymaster,
) async {
  // Get the encoded data for batch execution.
  var encodeBatchParamHex = _getExecuteBatchEncodedData();

  // Generate a user operation, considering whether to use the default paymaster.
  RPCResult res = await _generateUserOp(
    encodeBatchParamHex,
    useDefaultPaymaster ?? this.usePaymaster,
  );

  // Fetch the personal signature for the user operation.
  final String signature =
      await fetchSignature(res.userOpHash!, this.signer, true);
  // Send the signed user operation to the Ethereum network.
  final String userOpHash = await RPCCall().sendSignedOp(
    signature,
    res.userOp!,
    useDefaultPaymaster ?? this.usePaymaster,
    this.bundlerURL,
    this.entryPointAddress,
    this.paymasterConfig,
  );

  // Return the user operation hash.
  return userOpHash;
}