# Middleware

> What is Middleware?

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

The [Smart Account Client](/docs/wallets/concepts/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.

## Middleware order

<Tip>
  When using the [React](/docs/wallets/react/quickstart),
  [Core](/docs/wallets/core/overview), or
  [Infra](/docs/wallets/reference/account-kit/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.
</Tip>

As mentioned above, the client can be configured with a series of middleware that always run in the same order:

1. `dummyPaymasterAndData` - Generates a dummy paymaster and data for gas estimation if using a paymaster (default: noop)
2. `feeEstimator` - Estimates the fees for a transaction. If you are using Wallet APIs RPCs, use the [`alchemyFeeEstimator`](/docs/wallets/reference/account-kit/infra) middleware.
3. `gasEstimator` - Estimates the gas limits for a transaction. The default middleware calls the underlying RPC to `eth_estimateUserOperationGas`.
4. `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)
5. `paymasterAndData` - Requests gas sponsorship. (default: noop)
6. `userOperationSimulator` - Simulates a transaction to check if it will be successful. (default: noop)