---
eip: 5792
label: EIP-5792
title: Wallet Call API
status: Final
type: Standards Track
category: Interface
created: 2022-10-17
requires: 1193
official: https://eips.ethereum.org/EIPS/eip-5792
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-5792.md
canonical: https://eips.huatuo.xyz/zh/eip-5792/
lang: zh
tldr: 新增 wallet_sendCalls 及配套的 RPC 方法，使 dApp 可以请求钱包发送一批调用（可选择原子执行），并使用 paymaster 等钱包功能。
tags: [wallet, json-rpc, batching, account-abstraction, interface]
---

# EIP-5792: Wallet Call API

> Adds JSON-RPC methods for sending multiple calls from the user's wallet, and checking their status

**TL;DR:** 新增 wallet_sendCalls 及配套的 RPC 方法，使 dApp 可以请求钱包发送一批调用（可选择原子执行），并使用 paymaster 等钱包功能。

## 它解决什么问题？

dApp 主要通过 `eth_sendTransaction` 和 `eth_getTransactionReceipt` 与钱包交互。这些方法恰好只发送一笔交易，并且对智能账户一无所知。一次简单的"先 approve 再 swap"需要两次弹窗和两笔交易；即使钱包支持 paymaster（gas 代付），应用也无法要求钱包使用它。

EIP-5792 定义了一套新的 `wallet_` API：应用交出一个调用列表，由钱包决定如何执行（智能账户用一笔批量交易，普通 EOA 则用多笔），应用还可以发现钱包支持哪些额外功能。

## 它如何运作

四个 JSON-RPC 方法：

- **`wallet_sendCalls`**：接收 `version`、`chainId`、可选的 `from`、`atomicRequired`、一个由 `{to, data, value}` 组成的调用列表，以及可选的 `capabilities`。返回一个批次 `id`。调用必须按顺序、在指定的链上、从指定的地址执行。
- **`wallet_getCallsStatus(id)`**：返回数字 `status`（100 待处理，200 已确认，400 链下失败，500 完全回滚，600 部分回滚）、该批次是否以 `atomic` 方式运行，以及仅包含你的调用所产生日志的收据。
- **`wallet_showCallsStatus(id)`**：请求钱包向用户展示该批次。
- **`wallet_getCapabilities(address, chainIds?)`**：按链返回支持的 capability（键为十六进制链 ID；`"0x0"` 表示所有链）。

**原子性**是一项内置 capability，状态为 `supported`、`ready`（经用户批准后可以升级，例如通过 [EIP-7702](/eip-7702/) 升级 EOA）或 `unsupported`。如果设置 `atomicRequired: true`，钱包必须原子且连续地执行所有调用，否则拒绝。

**Capability** 是可扩展的。钱包不认识的 capability 会导致拒绝（错误 5700），除非应用将其标记为 `optional: true`。面向 [ERC-4337](/eip-4337/) 账户的 paymaster 服务是典型例子。新的 capability 由单独的 ERC 定义。

## 示例代码

在一次请求中完成 approve 和 swap，并在不支持批量时回退：

```ts
const [from] = await window.ethereum.request({ method: "eth_requestAccounts" });
const chainId = "0x1";

const caps = await window.ethereum.request({
  method: "wallet_getCapabilities",
  params: [from, [chainId]],
});
const atomic = caps?.[chainId]?.atomic?.status; // "supported" | "ready" | "unsupported"

const { id } = await window.ethereum.request({
  method: "wallet_sendCalls",
  params: [{
    version: "2.0.0",
    chainId,
    from,
    atomicRequired: atomic === "supported" || atomic === "ready",
    calls: [
      { to: TOKEN, data: approveCalldata },
      { to: ROUTER, data: swapCalldata },
    ],
  }],
});

const status = await window.ethereum.request({
  method: "wallet_getCallsStatus",
  params: [id],
});
if (status.status === 200) console.log(status.receipts);
```

## 需要注意

- **状态：Final。** 当钱包没有实现这些方法时，应用仍应回退到 `eth_sendTransaction`。
- 没有 `atomicRequired` 时，EOA 钱包可能把这些调用作为独立交易发送，因此后面的调用可能在前面的调用失败之后仍然执行。请检查 `atomic` 以及每个收据的状态。
- 钱包应在提交后至少 24 小时内保持批次状态可查询。
- 批次 ID 必须在每个发送者、每个应用内唯一；重复使用会被拒绝（错误 5720）。
- 为了限制指纹识别，`wallet_getCapabilities` 应当只对已连接到该应用的地址作出回应。钱包也可以通过带外方式公开 capability（例如配合 [EIP-6963](/eip-6963/) 的发现机制）。


---

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