---
eip: 7677
label: ERC-7677
title: Paymaster Web Service Capability
status: Review
type: Standards Track
category: ERC
created: 2024-04-03
requires: 4337, 5792
official: https://eips.ethereum.org/EIPS/eip-7677
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7677.md
canonical: https://eips.huatuo.xyz/zh/eip-7677/
lang: zh
tldr: 让应用告诉智能钱包应由哪个 paymaster Web 服务来赞助其 gas，并标准化钱包与该服务通信所用的两个 JSON-RPC 调用。
tags: [account-abstraction, paymaster, wallet, gas-sponsorship, rpc]
---

# ERC-7677: Paymaster Web Service Capability

> A way for apps to communicate with smart wallets about paymaster web services

**TL;DR:** 让应用告诉智能钱包应由哪个 paymaster Web 服务来赞助其 gas，并标准化钱包与该服务通信所用的两个 JSON-RPC 调用。

## 它解决什么问题？

在 [ERC-4337](/eip-4337/) 智能账户中，*paymaster* 可以代用户支付 gas。实践中 paymaster 以 Web 服务的形式运行：应用向提供商注册并获得一个 URL。但应用没有标准方式告诉用户的钱包"这些调用请使用这个 paymaster"，而且每家提供商暴露的 API 都略有不同，钱包因此无法通用地集成它们。

ERC-7677 同时解决了这两方面：一个携带应用所指定 paymaster URL 的钱包 capability，以及一套每个 paymaster 服务都要实现的通用双方法 API。

## 它如何运作

**Paymaster 服务 API。** 两个方法接收相同的参数：`[userOp, entryPoint, chainId, context]`。user operation 尚未签名，`context` 中是提供商特定的字段（例如策略 ID）。

- `pm_getPaymasterStubData` 返回仅用于 gas 估算的占位 paymaster 字段。对于 EntryPoint v0.7，它还必须返回 `paymasterPostOpGasLimit`，因为 post-op 由 paymaster 付费，不能信任钱包的估算。它可以返回钱包可展示的 `sponsor` 对象（`name`，以及可选的 data URI 形式的 `icon`），如果不需要第二次调用，还可以返回 `isFinal: true`。
- `pm_getPaymasterData` 在 gas 数值确定后返回真正的 paymaster 字段（v0.6 为 `paymasterAndData`，v0.7 为 `paymaster` + `paymasterData`）。随后用户签名。

stub 数据必须与最终数据长度相同，零字节不能更多，并且在 `validatePaymasterUserOp`/`postOp` 中走相同的代码路径；否则 `preVerificationGas` 或 gas 上限会被低估。

**钱包 capability。** 基于 [EIP-5792](/eip-5792/)：

1. 钱包在 `wallet_getCapabilities` 中按链声明 `paymasterService: { supported: true }`。
2. 应用在 `wallet_sendCalls` 中传入 `paymasterService: { url, context }`。
3. 钱包调用 stub 数据，用自己的 bundler 估算 gas，调用 paymaster 数据，请用户签名，然后提交。

gas 估算有意留给钱包，因为只有钱包知道自己会使用哪个 bundler。chain ID 参数让提供商可以按需用一个 URL 服务多条链。

## 示例代码

应用端，使用 EIP-1193 provider：

```ts
const caps = await provider.request({
  method: "wallet_getCapabilities",
  params: [account],
});

if (caps["0x2105"]?.paymasterService?.supported) {
  await provider.request({
    method: "wallet_sendCalls",
    params: [{
      version: "1.0",
      chainId: "0x2105",
      from: account,
      calls: [{ to: target, value: "0x0", data: calldata }],
      capabilities: {
        paymasterService: {
          url: "https://my-app.example/api/paymaster", // your backend proxy
          context: { policyId: "my-policy" },          // provider-defined
        },
      },
    }],
  });
}
```

EntryPoint v0.7 的 stub 数据响应：

```json
{
  "sponsor": { "name": "My App" },
  "paymaster": "0x...",
  "paymasterData": "0x...",
  "paymasterPostOpGasLimit": "0x..."
}
```

## 需要注意

- 状态为 **Review**：最终定稿前接口仍可能变化。
- paymaster 提供商的 URL 通常包含 API 密钥。规范建议让 capability 指向你自己的后端，由后端代理到提供商，并可在赞助前执行自己的检查。
- 钱包可能会忽略你的 paymaster（服务失败时，或用户选择了钱包自带的 paymaster），因此应用不能假定自己的 paymaster 确实付了费。
- 展示赞助方图标的钱包必须用 `<img>` 标签渲染 SVG，以免嵌入的脚本被执行。
- paymaster 服务应在 stub 数据这一步就拒绝它们不愿赞助的操作。


---

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