---
eip: 2256
label: EIP-2256
title: wallet_getOwnedAssets JSON-RPC Method
status: Stagnant
type: Standards Track
category: Interface
created: 2019-08-29
requires: 55, 155, 1474
official: https://eips.ethereum.org/EIPS/eip-2256
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2256.md
canonical: https://eips.huatuo.xyz/zh/eip-2256/
lang: zh
tldr: 提出 wallet_getOwnedAssets RPC 方法，使 dapp 能在获得许可后向用户钱包询问用户持有的代币，而不必自己扫描代币列表。
tags: [json-rpc, wallet, assets, tokens, privacy]
---

# EIP-2256: wallet_getOwnedAssets JSON-RPC Method

> This is a proposal for a new JSON-RPC call for retrieving from a wallet a selection of owned assets by an Ethereum address, with the user's permission.

**TL;DR:** 提出 wallet_getOwnedAssets RPC 方法，使 dapp 能在获得许可后向用户钱包询问用户持有的代币，而不必自己扫描代币列表。

## 它解决什么问题？

需要了解用户持有哪些代币的 dapp（例如用于税务计算，或让用户选择支付代币）没有标准方式去询问。它必须自己维护一份热门代币合约的列表，并逐个查询余额。每个 dapp 都在重复这项工作，结果要么不完整（遗漏代币），要么被不想要的空投搞得杂乱。

用户的钱包本来就知道用户关心哪些资产。EIP-2256 提议让 dapp 直接向钱包询问，并由用户批准共享的内容。它是对 [EIP-747](/eip-747/)（`wallet_watchAsset`）的补充，后者的方向相反：由 dapp 向钱包建议一个需要追踪的代币。

## 它如何运作

dapp 调用 `wallet_getOwnedAssets`，参数为：

- `address`：被请求资产的账户。
- 一个可选的选项对象：
  - `chainId`：限制在某一条链上（[EIP-155](/eip-155/) 链 ID）。
  - `limit`：dapp 希望返回的资产数量上限。
  - `types`：接口标识符，例如 `["ERC20", "ERC721"]`。
  - `justification`：向用户展示的、人类可读的理由（建议提供）。

钱包会弹出提示。用户可以接受、拒绝，或缩小选择范围。返回结果是一个记录数组，包含 `address`、`chainId`、`type` 以及资产特定的 `options`（对于 ERC-20：`name`、`symbol`、`icon`、`balance`、`decimals`）。只会返回钱包已经为该账户追踪的资产。

## 示例代码

请求：

```json
{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "wallet_getOwnedAssets",
  "params": [
    "0x3333333333333333333333333333333333333333",
    {
      "chainId": 1,
      "limit": 1,
      "types": ["ERC20"],
      "justification": "Select the token you want to pay with."
    }
  ]
}
```

响应示例：

```json
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": [
    {
      "address": "0x0000000000000000000000000000000000000001",
      "chainId": 1,
      "type": "ERC20",
      "options": { "name": "TokenA", "symbol": "TKA", "balance": 1000000000000, "decimals": 18 }
    }
  ]
}
```

通过 [EIP-1193](/eip-1193/) provider 调用，并带有回退：

```ts
async function getOwnedAssets(account: string) {
  try {
    return await window.ethereum.request({
      method: "wallet_getOwnedAssets",
      params: [account, { types: ["ERC20"], justification: "Show your balances" }],
    });
  } catch {
    return null; // method not supported or user rejected: fall back to your own token list
  }
}
```

## 需要注意

- **状态：Stagnant。** 主流钱包通常没有实现该方法，因此务必处理"方法未找到"和用户拒绝的情况。
- 返回的余额来自钱包，而不是链上。在将其用于任何重要用途之前，请在链上重新读取余额。
- 持仓列表属于敏感信息。因此规范将用户同意和 `justification` 文本放在核心位置；dapp 应只请求自己需要的内容（`types`、`chainId`、`limit`）。
- 该规范建立在 [EIP-1474](/eip-1474/) 的 JSON-RPC 约定之上。相关的钱包方法包括 [EIP-3085](/eip-3085/) 的 `wallet_addEthereumChain`。


---

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