> ## Documentation Index
> Fetch the complete documentation index at: https://docs.safefoundation.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Safe and ERC-4337

> How to use ERC-4337 with Safe Smart Accounts

Safe has adopted a modular and flexible approach to integrating the ERC-4337, allowing users to turn their Safe account into an ERC-4337 smart account.

Safe ERC-4337 compatibility is provided via [Safe Modules](/more/glossary#safe-module) and the Fallback Handler. This means the functionality is not implemented directly in the Safe Smart Account, but in the [Safe4337Module](https://github.com/safe-fndn/safe-modules/blob/main/modules/4337/contracts/Safe4337Module.sol) contract, which can be enabled in any Safe account at the Safe deployment time or afterward.

## Safe4337Module

This module is an extension to the Safe Smart Account that acts both as a Fallback Handler, meaning that the Safe Proxy contract will fallback to this contract when its functions are called in the proxy, and a Safe Module, having the right to execute Safe transactions once it's enabled in a Safe account.

It implements the ERC-4337 interface, including the functions to validate and execute the user operation, and it's limited to the `EntryPoint` address.

<Info>
  This module must only be used with Safe [v1.4.1](https://github.com/safe-fndn/safe-smart-account/blob/v1.4.1/CHANGELOG.md) or newer.
</Info>

### UserOperation validation

The Safe Proxy contract receives a call to the `validateUserOp` function from the `EntryPoint` and forwards it to the `Safe4337Module`. The module validates the `UserOperation` object by checking that the Safe owners signed the `UserOperation` hash and returns the result. It also executes a module transaction to pay the fees back.

<img src="https://mintcdn.com/safeecosystemfoundation/vlKLZb4hy_M_30i6/assets/diagram-4337-validate.png?fit=max&auto=format&n=vlKLZb4hy_M_30i6&q=85&s=46d34668c30d82d8dd19254197542e8c" alt="diagram validate UserOp" width="2798" height="1256" data-path="assets/diagram-4337-validate.png" />

### UserOperation execution

After successful validation, the `EntryPoint` calls the `executeUserOp` function, forwarding it again to the module, which executes a module transaction with the target and data specified in the `UserOperation` object.

<img src="https://mintcdn.com/safeecosystemfoundation/vlKLZb4hy_M_30i6/assets/diagram-4337-execute.png?fit=max&auto=format&n=vlKLZb4hy_M_30i6&q=85&s=d7ebc7b86a025a6d739211b76c8b3fe4" alt="diagram execute UserOp" width="2798" height="1256" data-path="assets/diagram-4337-execute.png" />
