attachPaymaster method

bool attachPaymaster(
  1. Paymaster paymaster
)

Attaches a paymaster to the current paymaster instance, which can be used to pay for gas in user operations (userops).

This function sets the current paymaster for the instance, enabling the use of this paymaster to cover gas costs in user operations.

Parameters:

  • paymaster: An instance of the Paymaster class that contains information about the paymaster, including ABI, contract, signer, and contract instance.

Returns:

  • true if the paymaster is successfully attached.
  • Throws an exception with an error message if an exception occurs during the process.

Implementation

bool attachPaymaster(Paymaster paymaster) {
  try {
    // Set the flag to indicate that a paymaster is in use.
    this.usePaymaster = true;

    // Set the default paymaster to the provided paymaster instance.
    this.defaultPaymaster = paymaster;

    // Return true to indicate successful attachment.
    return true;
  } on Exception catch (e) {
    // Print any exception that occurs during the process, then throw a new exception with an error message.
    print(e);
    throw Exception("Could not attach paymaster");
  }
}