---
eip: 7811
label: ERC-7811
title: Wallet Asset Discovery
status: Draft
type: Standards Track
category: ERC
created: 2024-11-07
requires: 20, 155, 721, 5792
official: https://eips.ethereum.org/EIPS/eip-7811
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7811.md
canonical: https://eips.huatuo.xyz/zh/eip-7811/
lang: zh
tldr: 新增 wallet_getAssets JSON-RPC 方法，让钱包可以准确告诉 dapp 用户跨链持有哪些资产，包括钱包知道、而 dapp 难以在链上找到的余额。
tags: [wallet, json-rpc, assets, multichain, dapps]
---

# ERC-7811: Wallet Asset Discovery

> JSON-RPC method for wallets to share a user’s full asset list with Dapps, including assets not easily found through on-chain data alone

**TL;DR:** 新增 wallet_getAssets JSON-RPC 方法，让钱包可以准确告诉 dapp 用户跨链持有哪些资产，包括钱包知道、而 dapp 难以在链上找到的余额。

## 它解决什么问题？

dapp 通常自己读取链上数据来推算用户的余额：每条链每种代币一次 RPC 调用，而且只覆盖它们想得到要检查的链。它们会漏掉其他链或其他账户上的资产，还可能阻止某个钱包其实能够处理的操作（兑换或支付），例如从另一条链调度资金。

钱包本来就知道用户的资产组合，其中往往包括很难在链上找到的资产。ERC-7811 让 dapp 直接向钱包询问即可。

## 它如何运作

**请求** `wallet_getAssets`，参数包括：

- `account`（必填）：要报告的地址。
- `assetFilter`（可选）：按 [EIP-155](/eip-155/) 链 ID 指定的精确资产，形式为 `{ address, type }`（`address` 可以是 `"native"`）。如果提供，钱包只返回这些资产，并**忽略另外两个过滤器**。
- `assetTypeFilter`（可选）：例如 `["erc20", "native"]`。
- `chainFilter`（可选）：十六进制链 ID 的列表。

没有 `assetFilter` 时，钱包应返回它所知道的全部资产，最好按估算价值排序。希望 dapp 尽可能收窄过滤范围，以保持调用轻量、快速。

**响应：**一个以十六进制链 ID 为键的对象，每个键下是一个 `{ address, balance, type, metadata }` 的列表，其中 `balance` 为十六进制。常见类型规定了最低限度的 `metadata`：

- `native`：无需元数据。
- `erc20`：`name`、`symbol`、`decimals`。
- `erc721`：`name`、`symbol`、`tokenId`，以及可选的 `tokenURI`。

**发现：**支持 [ERC-5792](/eip-5792/) 的钱包应在 `wallet_getCapabilities` 中为每条链声明 `{ "assetDiscovery": { "supported": true } }`；使用 CAIP-25 的钱包在其 `eip155` 会话范围内列出该方法。

## 示例代码

```ts
// window.ethereum: an EIP-1193 provider
const [account] = await window.ethereum.request({ method: "eth_requestAccounts" });

const assets = await window.ethereum.request({
  method: "wallet_getAssets",
  params: [{
    account,
    assetTypeFilter: ["native", "erc20"],
    chainFilter: ["0x1", "0xa"],          // Ethereum mainnet, OP Mainnet
  }],
});

for (const [chainId, list] of Object.entries(assets)) {
  for (const a of list as any[]) {
    console.log(chainId, a.type, a.metadata?.symbol ?? "native", BigInt(a.balance));
  }
}
```

## 需要注意

- 状态为 **Draft**，Rationale 和 Security Considerations 两节仍是 TODO。
- 这些数据是**钱包**的声明。不要把它当作任何安全敏感场景下的资金证明；在重要的地方请在链上验证。
- `type` 是自由格式的字符串。规范自己的示例里 `"erc20"` 和 `"ERC20"` 混用，因此比较类型时要忽略大小写。
- 并非所有钱包都实现了它；请先检查 `wallet_getCapabilities`，并回退到链上读取。


---

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