---
eip: 7896
label: EIP-7896
title: ABI attachment in `wallet_sendCalls`
status: Stagnant
type: Standards Track
category: Interface
created: 2025-02-27
requires: 5792
official: https://eips.ethereum.org/EIPS/eip-7896
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7896.md
canonical: https://eips.huatuo.xyz/zh/eip-7896/
lang: zh
tldr: 为 wallet_sendCalls 增加 `interfaces` 能力，让 dapp 附带合约 ABI，使钱包能够解码 calldata，向用户展示他们正在签署的内容，而不是原始十六进制。
tags: [wallet, rpc, abi, security, capabilities]
---

# EIP-7896: ABI attachment in `wallet_sendCalls`

> A capability to enable calldata decoding in wallets.

**TL;DR:** 为 wallet_sendCalls 增加 `interfaces` 能力，让 dapp 附带合约 ABI，使钱包能够解码 calldata，向用户展示他们正在签署的内容，而不是原始十六进制。

## 它解决什么问题？

"盲签"是以太坊最大的用户安全问题之一。当 dapp 请求钱包发送交易时，钱包收到的 `data` 是一段不透明的字节串。要显示有意义的内容（"向 0xf0c8… 转账 100 个代币"），钱包必须猜测合约的 ABI，要么依靠 4 字节 selector 数据库（对新合约无效，还可能被刻意制造的 selector 碰撞欺骗），要么依靠已验证源码的服务（中心化）。

交易模拟有帮助，但无法预测所有结果。而 dapp 总是知道自己构造调用时所用的 ABI。这份 EIP 让它把这份 ABI 交给钱包。

## 它如何运作

它用一个名为 `interfaces` 的新能力扩展了 [EIP-5792](/eip-5792/) 的批量调用 API：

- 在 `wallet_sendCalls` 请求中，`capabilities.interfaces` 将合约地址（通常是 `calls` 中的 `to` 地址）映射到 `{ version, spec }`。
- 定义了两个版本：`abi-v1` 和 `abi-v2`，分别对应 Solidity 的 ABI coder v1 和 v2。`spec` 是标准的 Solidity JSON ABI 数组。它可以包含事件和错误，但应当精简到相关的部分。
- dapp 应当设置 `optional: true`，这样请求在不支持该能力的钱包上仍可使用。
- 支持该能力的钱包应当用所提供的 ABI 解码每次调用的 `data` 并显示参数。它们可以对照已验证或受信任规范的数据库来交叉检查 ABI。
- `wallet_getCapabilities` 通过 `versions` 数组声明支持情况，例如 `["abi-v1", "abi-v2"]`。

## 示例代码

一个附带了 ERC-20 `transfer` ABI 的 `wallet_sendCalls` 请求：

```ts
await provider.request({
  method: "wallet_sendCalls",
  params: [{
    version: "1.0",
    from: account,
    chainId: "0x1",
    calls: [{ to: token, value: "0x0", data: transferCalldata }],
    capabilities: {
      interfaces: {
        optional: true,
        [token]: {
          version: "abi-v2",
          spec: [{
            type: "function", name: "transfer", stateMutability: "nonpayable",
            inputs: [{ name: "to", type: "address" }, { name: "value", type: "uint256" }],
            outputs: [{ name: "", type: "bool" }],
          }],
        },
      },
    },
  }],
});
```

先检查钱包是否支持：

```json
{ "0x0": { "interfaces": { "supported": true, "versions": ["abi-v1", "abi-v2"] } } }
```

## 需要注意

- **状态：Stagnant。** 这份提案近期没有任何动静，其 Rationale 和 Security Considerations 部分仍是 TODO。不应假设钱包已支持。
- 附带的 ABI 由 dapp 提供，而 dapp 本身可能是恶意的。它提升的是*可读性*，而不是可信度；建议钱包对照受信任的来源进行验证。
- `interfaces` 中的地址与 `to` 地址是区分大小写比较的，所以请使用一致的大小写。
- 构建在 [EIP-5792](/eip-5792/) 之上，钱包通过标准的 [EIP-1193](/eip-1193/) provider 暴露它。


---

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