# ERC-4337 Deep Dive

> The Account Abstraction standard — the technology that makes crypto simple.

***

## What Is ERC-4337?

**ERC-4337** is an Ethereum standard for **Account Abstraction**. It enables "smart wallets" (Smart Accounts) with extended functionality, without changes to the Ethereum protocol itself.

Before ERC-4337, wallets were simple — a key signs a transaction, the transaction is paid in ETH. With ERC-4337, the wallet becomes **programmable**.

***

## Key Components

### UserOperation

Instead of a regular transaction, the user creates a **UserOperation** — a description of what they want to do:

```
UserOperation {
  sender         Smart Account address
  nonce          Operation sequence number
  initCode       Code to create SA (if not yet deployed)
  callData       What to execute (transfer, swap, etc.)

  callGasLimit           Gas limit for execution
  verificationGasLimit   Gas limit for verification
  preVerificationGas     Gas before verification
  maxFeePerGas           Maximum gas price
  maxPriorityFeePerGas   Priority fee

  paymasterAndData   Paymaster data (if sponsored)
  signature          Owner's signature
}
```

### EntryPoint

The **single entry point** — a smart contract that:

1. Receives UserOperations from the Bundler
2. Verifies the owner's signature
3. Executes the operation through the Smart Account
4. Settles gas with the Paymaster

EntryPoint is the same contract on all EVM networks (standardized address).

### Bundler

The **packaging service** — collects UserOperations from users and submits them to the blockchain as a regular transaction to EntryPoint.

### Paymaster

The **gas sponsor** — a smart contract that can pay gas for the user. Signs permission in `paymasterAndData`, and EntryPoint charges gas from it.

***

## Transaction Flow

```
┌──────────┐     ┌──────────┐     ┌──────────┐     ┌──────────┐
│          │     │          │     │          │     │          │
│  Wallet  │────▶│ Paymaster│────▶│ Bundler  │────▶│EntryPoint│
│  App     │     │          │     │          │     │(on-chain)│
│          │     │          │     │          │     │          │
└──────────┘     └──────────┘     └──────────┘     └──────────┘
                                                        │
  1. Create        2. Get gas +     3. Submit to    4. Verify
     UserOp          paymaster       mempool         and execute
                     data
```

### In Detail:

1. **Wallet App** creates a UserOperation with `callData` (what to do) and `nonce`
2. **Paymaster** adds gas data and its signature (`paymasterAndData`)
3. Wallet App **signs** the UserOp hash with the EOA key
4. **Bundler** accepts the signed UserOp and submits it to the blockchain
5. **EntryPoint** verifies signature → executes callData → charges Paymaster for gas

***

## Lazy Deployment

Smart Account doesn't need to be created in advance. On the first transaction, `initCode` in the UserOperation contains the deployment instruction:

```
First transaction:
  initCode = [factory.createAccount(owner, salt)]  ← deploy SA
  callData = [transfer(to, amount)]                ← and immediately execute transfer
```

Bundler and EntryPoint handle both actions in a single transaction.

***

## CREATE2 — Deterministic Address

The Smart Account address is computed **mathematically**, before creation:

```
SA_address = CREATE2(factory, keccak256(owner + salt))
```

Same parameters = same address on **any** EVM network. That's why your SA address is identical on Base, Arbitrum, Polygon, and all others.

***

## Batch Operations

Smart Account can execute **multiple calls** in a single UserOperation:

```
UserOperation.callData = executeBatch([
  approve(USDC, spender, amount),
  swap(USDC, ETH, amount),
  collectFee(treasury, feeAmount)
])
```

Three operations — one signature, one transaction, one gas payment.

***

## ERC-4337 Advantages

| Property                | Regular Wallet (EOA) | Smart Account (ERC-4337) |
| ----------------------- | :------------------: | :----------------------: |
| Gas payment             |       ETH only       |    ETH, USDC, or free    |
| Batch operations        |          No          |            Yes           |
| Custom logic            |          No          |            Yes           |
| Recovery                |   Seed phrase only   | Social recovery (future) |
| Same address all chains |          Yes         |       Yes (CREATE2)      |
| Sponsorship             |          No          |         Paymaster        |
