The Smart Account Client is extended with a series of middleware. When building transactions for signing and sending, the flow can be involved.
Sending a transaction requires getting the latest nonce for an account, checking if the account is deployed to set the initCode or factory and factoryData, estimating fees, estimating gas, and then signing the transaction.
If you want to sponsor gas, you need to generate some dummyPaymasterAndData to use during gas estimation, and after estimating gas you can request gas sponsorship.
Middleware allows you to avoid having to write the same flows over and over when all you want to do is call a contract with some data or send some ETH to a destination.
When using the React,
Core, or
Infra packages, the Smart Account
Clients are already configured to use the appropriate middleware for your
needs. If you want to sponsor gas, the Smart Account Clients in these packages
abstract the relevant middleware away since all you need is a
policyId to sponsor gas.
As mentioned above, the client can be configured with a series of middleware that always run in the same order:
dummyPaymasterAndData- Generates a dummy paymaster and data for gas estimation if using a paymaster (default: noop)feeEstimator- Estimates the fees for a transaction. If you are using Smart Wallets RPCs, use thealchemyFeeEstimatormiddleware.gasEstimator- Estimates the gas limits for a transaction. The default middleware calls the underlying RPC toeth_estimateUserOperationGas.customMiddleware- Allows you to define custom middleware to run before requesting sponsorship if there are any additional steps you need to take before requesting sponsorship. (default: noop)paymasterAndData- Requests gas sponsorship. (default: noop)userOperationSimulator- Simulates a transaction to check if it will be successful. (default: noop)