---
eip: 7836
label: ERC-7836
title: Wallet Call Preparation API
status: Draft
type: Standards Track
category: ERC
created: 2024-12-06
requires: 1193, 5792
official: https://eips.ethereum.org/EIPS/eip-7836
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7836.md
canonical: https://eips.huatuo.xyz/zh/eip-7836/
lang: zh
tldr: 新增 wallet_prepareCalls 和 wallet_sendPreparedCalls，让持有会话密钥的应用可以向钱包询问任意智能账户需要签署什么，自己完成签名，再交还给钱包去执行。
tags: [wallet, json-rpc, session-keys, smart-accounts, draft]
---

# ERC-7836: Wallet Call Preparation API

> Adds JSON-RPC methods for requesting unsigned EIP-5792 calls based on the wallet's implementation, and then sending those calls once signed.

**TL;DR:** 新增 wallet_prepareCalls 和 wallet_sendPreparedCalls，让持有会话密钥的应用可以向钱包询问任意智能账户需要签署什么，自己完成签名，再交还给钱包去执行。

## 它解决什么问题？

应用越来越多地使用**会话密钥**或限定范围的权限代表用户行事，例如一个自动执行 DEX 交易、不必为每笔交易都弹出钱包窗口的应用。问题在于：每个智能合约账户都有自己的执行接口和签名格式。要为任意账户签署一批调用，应用就得知道每种账户实现是如何构造并哈希其载荷的。

[EIP-5792](/eip-5792/) 的 `wallet_sendCalls` 已经让钱包可以打包并签署调用，但签名是由*钱包*完成的。ERC-7836 增加了一个两步流程：由钱包完成与账户相关的准备工作，由*应用的密钥*完成签名。

## 它如何运作

两个新的 JSON-RPC 方法，都通过 [EIP-1193](/eip-1193/) provider 调用：

**1. `wallet_prepareCalls`** 接受与 `wallet_sendCalls` 相同的结构（`calls`、`capabilities`、`chainId`、可选的 `from`、`version`），外加一个可选的 `key` 提示：公钥及其类型（`secp256k1`、`p256`、`webauthn-p256`），以及是否预哈希。钱包构造与账户相关的载荷，并返回：

- `digest`：密钥必须签署的确切字节
- `context`：不透明的、钱包专有的数据（例如 [ERC-4337](/eip-4337/) 的 UserOperation）
- `capabilities`、`chainId`、`key`、`version`：需原样转发

**2. `wallet_sendPreparedCalls`** 接受上述响应（去掉 `digest`）再加上 `signature`。钱包提交这批调用，并返回 `{ id, capabilities }`，与 `wallet_sendCalls` 相同，因此现有的状态轮询代码可以继续使用。

钱包仍然负责检查该密钥确实已在账户上获得授权，并且所请求的 capabilities 在该密钥的权限范围之内。

## 示例代码

准备、用会话密钥签名并发送（TypeScript）：

```ts
const provider = (window as any).ethereum;

const { digest, ...prepared } = await provider.request({
  method: "wallet_prepareCalls",
  params: [{
    version: "1",
    chainId: "0x1",
    from: account,
    calls: [{ to: target, data: calldata }],
    key: { type: "p256", publicKey: sessionPublicKey, prehash: false },
  }],
});

// Sign the wallet-provided digest with the app's session key
const signature: `0x${string}` = await signWithSessionKey(digest);

const { id } = await provider.request({
  method: "wallet_sendPreparedCalls",
  params: [{ ...prepared, signature }],
});

// Track it like any EIP-5792 bundle
const status = await provider.request({ method: "wallet_getCallsStatus", params: [id] });
```

## 需要注意

- **状态：Draft。** 方法名和字段仍可能变化。
- 它不会修改或取代 `wallet_sendCalls`；只支持 EIP-5792 的钱包不受影响。
- `prehash` 必须一致处理。不一致（二次哈希与已预哈希输入之间的错配）会悄悄产生无效签名。
- 钱包应当能根据回传的内容重新计算 `digest`，并可以强制有效期窗口，以防止过期或被重放的准备数据。
- 让会话密钥保持不可导出且限定范围；绝不要把不透明的 `digest` 当作需要用户批准的内容展示给用户。
- 对于普通的链下消息签名，请参阅相关的 [ERC-7871](/eip-7871/) `wallet_sign`。


---

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