---
eip: 7679
label: ERC-7679
title: UserOperation Builder
status: Draft
type: Standards Track
category: ERC
created: 2024-04-05
requires: 4337
official: https://eips.ethereum.org/EIPS/eip-7679
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7679.md
canonical: https://eips.huatuo.xyz/zh/eip-7679/
lang: zh
tldr: "让每个 ERC-4337 智能账户发布一个链上的\"builder\"合约，封装自己的 nonce、calldata 和签名编码方式，这样任何钱包或 dapp 都无需账户专属 SDK 就能构造 UserOperation。"
tags: [account-abstraction, smart-accounts, userop, interoperability]
---

# ERC-7679: UserOperation Builder

> Construct UserOperations without being coupled with account-specific logic.

**TL;DR:** 让每个 ERC-4337 智能账户发布一个链上的"builder"合约，封装自己的 nonce、calldata 和签名编码方式，这样任何钱包或 dapp 都无需账户专属 SDK 就能构造 UserOperation。

## 它解决什么问题？

[ERC-4337](/eip-4337/) 允许智能账户发送 UserOperation（UserOp），但把三个字段留给各账户实现自行决定：`nonce`、`callData` 和 `signature`。有的账户暴露 `executeFoo`，有的暴露 `executeBar`；有的把验证器地址打包进 nonce，有的则用额外数据包装签名。

结果是，想要发送 UserOp 的 dapp 或钱包必须知道自己面对的是哪种账户实现，并集成该厂商的 SDK。这是厂商锁定，也让账户抽象生态变得碎片化。

ERC-7679 把这部分账户专属的编码逻辑搬到链上，放在一个通用接口之后。

## 它如何运作

每种智能账户实现都提供一个实现 `IUserOperationBuilder` 的 **UserOp builder** 合约：

| 函数 | 返回值 |
| --- | --- |
| `entryPoint()` | 该账户支持的 ERC-4337 EntryPoint |
| `getNonce(account, context)` | 应使用的 nonce |
| `getCallData(account, executions, context)` | 一批 `(target, value, callData)` 执行对应的 `callData` |
| `formatSignature(account, userOp, context)` | 按账户期望的格式包装后的原始签名 |

`context` 是账户所有者（或其钱包）交给构造方的不透明字节串，携带 builder 所需的任何信息，例如委托授权。

构造方的建议流程：

1. 从账户所有者处获取 builder 地址和 `context`。
2. 通过 `eth_call` 调用 `getNonce` 和 `getCallData`（最好批量调用）。
3. 用较低的 gas 值填充 UserOp 并签名，然后调用 `formatSignature`，得到用于 gas 估算、格式正确的**占位签名**（dummy signature）。
4. 估算 gas，填入真实的 gas 值，再次签名，并再调用一次 `formatSignature`，得到最终有效的 UserOp。

其他 UserOp 字段（gas、paymaster 等）不在范围内。对于尚未部署的账户，规范描述了一个受 [ERC-6492](/eip-6492/) 启发的 `CounterfactualCall` 合约：它在 `eth_call` 中通过工厂合约部署账户，然后再查询 builder。

## 示例代码

使用 ethers v6 构造 `callData` 和 `nonce`：

```ts
import { Contract, JsonRpcProvider } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const builder = new Contract(builderAddress, [
  "function entryPoint() view returns (address)",
  "function getNonce(address smartAccount, bytes context) view returns (uint256)",
  "function getCallData(address smartAccount, (address target, uint256 value, bytes callData)[] executions, bytes context) view returns (bytes)",
], provider);

const executions = [
  { target: tokenAddress, value: 0n, callData: transferData },
];

const [nonce, callData] = await Promise.all([
  builder.getNonce(account, context),
  builder.getCallData(account, executions, context),
]);
// Fill the rest of the UserOp, then call formatSignature(...) for the dummy and final signatures.
```

## 需要注意

- **状态：Draft。** 接口仍可能变化。
- 该接口面向 EntryPoint v0.7（`PackedUserOperation`）。使用 EntryPoint v0.6 的账户需要一个采用 v0.6 结构体的变体。
- 占位签名很重要：它消耗的 gas 必须与真实签名大致相当，因此它来自账户专属的 builder，而不是固定值。
- 占位签名是公开暴露的；规范建议用非常低的 gas 值对占位 UserOp 签名，这样即使被截获也毫无用处。
- 它与 [ERC-7579](/eip-7579/) 等模块化账户标准互为补充：后者标准化的是账户内部的执行和模块，而不是从外部构造 UserOp 的方式。


---

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