EIP-2256 · Stagnant · Interface · 2019-08-29
EIP-2256: wallet_getOwnedAssets JSON-RPC Method
Proposes a wallet_getOwnedAssets RPC method so a dapp can ask the user's wallet, with permission, for the tokens the user holds instead of scanning token lists itself.
What problem does it solve?
A dapp that needs to know a user's tokens, for tax calculation or to offer a choice of payment token, has no standard way to ask. It must keep its own list of popular token contracts and query a balance for each one. Every dapp duplicates this work, and the result is either incomplete (missing tokens) or cluttered with unwanted airdrops.
The user's wallet already knows which assets the user cares about. EIP-2256 proposes letting the dapp ask the wallet directly, with the user approving what is shared. It complements EIP-747 (wallet_watchAsset), which goes the other way: a dapp suggesting a token for the wallet to track.
How it works
The dapp calls wallet_getOwnedAssets with:
address: the account whose assets are requested.- An optional options object:
chainId: restrict to one chain (EIP-155 chain ID).limit: maximum number of assets the dapp wants back.types: interface identifiers such as["ERC20", "ERC721"].justification: human-readable reason shown to the user (recommended).
The wallet shows a prompt. The user can accept, reject, or narrow the selection. The result is an array of records containing address, chainId, type, and asset-specific options (for ERC-20: name, symbol, icon, balance, decimals). Only assets the wallet already tracks for that account are returned.
Sample code
Request:
{
"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."
}
]
}
Example response:
{
"id": 1,
"jsonrpc": "2.0",
"result": [
{
"address": "0x0000000000000000000000000000000000000001",
"chainId": 1,
"type": "ERC20",
"options": { "name": "TokenA", "symbol": "TKA", "balance": 1000000000000, "decimals": 18 }
}
]
}
Calling it through an EIP-1193 provider, with a fallback:
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
}
}
Things to know
- Status: Stagnant. Mainstream wallets do not generally implement this method, so always handle "method not found" and user rejection.
- Returned balances come from the wallet, not the chain. Re-read balances on-chain before relying on them for anything important.
- A list of holdings is sensitive. The spec makes user consent and the
justificationtext central for this reason; dapps should request only what they need (types,chainId,limit). - The spec builds on the JSON-RPC conventions of EIP-1474. Related wallet methods include EIP-3085
wallet_addEthereumChain.