---
eip: 4337
label: ERC-4337
title: Account Abstraction Using Alt Mempool
status: Final
type: Standards Track
category: ERC
created: 2021-09-29
requires: 712, 7702
official: https://eips.ethereum.org/EIPS/eip-4337
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-4337.md
canonical: https://eips.huatuo.xyz/ja/eip-4337/
lang: ja
tldr: プロトコルを変えずに実現するアカウント抽象化。スマートコントラクトウォレットが UserOperation を専用 mempool に送り、Bundler が EntryPoint コントラクト経由でオンチェーンに載せ、Paymaster がガス代を肩代わりできる。
tags: [account-abstraction, smart-wallet, bundler, paymaster, gasless]
---

# ERC-4337: Account Abstraction Using Alt Mempool

> Account abstraction without consensus-layer protocol changes, instead relying on higher-layer infrastructure.

**TL;DR:** プロトコルを変えずに実現するアカウント抽象化。スマートコントラクトウォレットが UserOperation を専用 mempool に送り、Bundler が EntryPoint コントラクト経由でオンチェーンに載せ、Paymaster がガス代を肩代わりできる。

## 何を解決するのか

通常の Ethereum アカウント（EOA）は融通が利きません。secp256k1 の秘密鍵 1 本だけ、紛失しても復旧できず、支出制限もなく、1 トランザクションにつき 1 呼び出し、しかもガス代のために ETH を保有する必要があります。スマートコントラクトウォレットならすべて実現できますが、コントラクトは自分からトランザクションを開始できません。EOA を持つ誰かが起動し、ガス代を払う必要があります。

以前の提案はこれをプロトコル内で解決しようとしましたが、ハードフォークと合意形成が必要です。ERC-4337 はコントラクトとオフチェーンのインフラだけで「アカウント抽象化」を実現するため、どの EVM チェーンでも今すぐ動きます。

## 仕組み

1. **UserOperation**。トランザクションの代わりに、ユーザーは `UserOperation` オブジェクトに署名します。`sender`（スマートアカウント）、`nonce`、`callData`、ガス上限、手数料フィールド、任意の `paymaster`、そして任意形式の `signature` を含みます。
2. **代替 mempool と Bundler**。UserOperation は専用の mempool に送られます。*Bundler* がそれを拾い、シミュレーションし、複数をまとめて 1 本の通常トランザクションとして `EntryPoint.handleOps(...)` を呼び、ガス代を支払います。
3. **EntryPoint**。監査済みの単一シングルトンコントラクト。各 op について送信元アカウントの `validateUserOp` を呼び（署名を検証し、ガス代を EntryPoint に支払う）、`callData` を実行し、Bundler に精算します。
4. **Paymaster**（任意）。op のガス代を肩代わりすることに同意するコントラクト。オンボーディングのスポンサー、ETH の代わりに ERC-20 トークンでの支払いなどに使われます。
5. **Factory**（任意）。アカウントが未デプロイなら、`initCode` / `factory` が同じ操作内でデプロイします。ユーザーの最初のアクションを counterfactual なアドレスから実行できます。

結果として、パスキー、マルチシグ、ソーシャルリカバリー、セッションキー、バッチ呼び出し、ガスレスオンボーディングを備えたウォレットが、プロトコル変更なしで実現します。

## サンプルコード

すべての ERC-4337 アカウントが実装するインターフェース（v0.7）:

```solidity
struct PackedUserOperation {
    address sender;
    uint256 nonce;
    bytes   initCode;            // factory アドレス ++ factoryData、または空
    bytes   callData;
    bytes32 accountGasLimits;    // verificationGasLimit (16 bytes) ++ callGasLimit (16 bytes)
    uint256 preVerificationGas;
    bytes32 gasFees;             // maxPriorityFeePerGas (16 bytes) ++ maxFeePerGas (16 bytes)
    bytes   paymasterAndData;    // paymaster ++ ガス上限 ++ paymasterData、または空
    bytes   signature;
}

interface IAccount {
    /// 署名が有効なら 0、無効なら 1 (SIG_VALIDATION_FAILED) を返す。
    /// missingAccountFunds が 0 でなければ EntryPoint へ送金すること。
    function validateUserOp(
        PackedUserOperation calldata userOp,
        bytes32 userOpHash,
        uint256 missingAccountFunds
    ) external returns (uint256 validationData);
}
```

1 本の EOA 鍵が所有する、あえて最小限にしたアカウント:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";

contract SimpleAccount is IAccount {
    address public immutable entryPoint;
    address public owner;

    constructor(address _entryPoint, address _owner) { entryPoint = _entryPoint; owner = _owner; }

    function validateUserOp(PackedUserOperation calldata op, bytes32 opHash, uint256 missing)
        external returns (uint256)
    {
        require(msg.sender == entryPoint, "only EntryPoint");
        address signer = ECDSA.recover(MessageHashUtils.toEthSignedMessageHash(opHash), op.signature);
        if (missing != 0) payable(entryPoint).call{value: missing}("");
        return signer == owner ? 0 : 1;
    }

    function execute(address to, uint256 value, bytes calldata data) external {
        require(msg.sender == entryPoint, "only EntryPoint");
        (bool ok, bytes memory ret) = to.call{value: value}(data);
        require(ok, string(ret));
    }
}
```

クライアントから操作を送る（viem の account-abstraction モジュール）:

```ts
import { createBundlerClient } from "viem/account-abstraction";
import { http } from "viem";
import { sepolia } from "viem/chains";

const bundler = createBundlerClient({
  account,                       // SmartAccount オブジェクト（toCoinbaseSmartAccount / toSimpleSmartAccount など）
  chain: sepolia,
  transport: http("https://your-bundler.example/rpc"),
});

const hash = await bundler.sendUserOperation({
  calls: [{ to: "0x...", value: 0n, data: "0x..." }],
  // paymaster: true,            // Paymaster にガス代を肩代わりさせる
});
const receipt = await bundler.waitForUserOperationReceipt({ hash });
```

内部では Bundler の JSON-RPC メソッド `eth_sendUserOperation(userOp, entryPoint)` が呼ばれます。

## 知っておくべきこと

- EntryPoint はバージョンごとに固定アドレスを持つ共有コントラクトです（v0.6 `0x5FF1…2789`、v0.7 `0x0000000071727De22E5E9d8BAf0edAc6f37da032`）。アカウントと Bundler はバージョンを揃える必要があります。
- 検証コードには制約があります。シミュレーションと実行の結果がずれるような `TIMESTAMP` 等の使い方は禁止され、ストレージアクセスも制限されます（[ERC-7562](/eip-7562/) 参照）。これが mempool をスパムから守っています。
- Bundler サービス（Alchemy、Pimlico、Biconomy、Candide、自前ホストなど）と、通常は Paymaster サービスが必要です。これらはインフラであってチェーンの一部ではありません。
- [EIP-7702](/eip-7702/) は既存の EOA をスマートアカウントのように振る舞わせます。ERC-4337 は 7702 アカウントをネイティブにサポートしており、両者は競合ではなく補完関係にあります。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-4337
