EIP-747 · Final · Interface · 2018-08-13
EIP-747: wallet_watchAsset RPC Method
Defines wallet_watchAsset, an RPC method that lets a dapp ask the user's wallet to start tracking a token, so users don't have to paste contract addresses by hand.
What problem does it solve?
Wallets show your token balances only for tokens they know about. Without a standard, they had two bad options:
- Keep a curated token list. That costs the wallet bandwidth to poll many contracts, gives it a security burden, and puts it under pressure to list obscure tokens.
- Make users add tokens by hand, by pasting a contract address and entering the symbol and decimals. That is a poor experience and easy to get wrong.
Showing every token automatically is not a fix either. Airdropped spam and phishing tokens would fill everyone's wallet. The spec's insight is that the best moment to add a token is when a user is on the token's own site and wants to see it.
How it works
A dapp calls the new method through the EIP-1193 provider with one object parameter:
interface WatchAssetParameters {
type: string; // asset interface, e.g. "ERC1046" or legacy "ERC20"
options: any; // fields depend on type
}
For both the ERC1046 and legacy ERC20 types, options.address is required and must be a 0x-prefixed, EIP-55 checksummed contract address. options.chainId is optional and defaults to the active chain. A bad checksum or an unknown chain makes the request invalid.
For ERC1046, the wallet must fetch the token's ERC-1046 tokenURI metadata. That gives it name, symbol and image without the dapp having to supply them.
The method returns true right away if the request is valid, before the user decides. This prevents a site from learning which tokens a user holds (fingerprinting). It returns an error if the request is invalid, for example an unsupported type, a blocked token, or failed metadata.
Sample code
From a dapp, with an injected provider:
const added = await window.ethereum.request({
method: "wallet_watchAsset",
params: {
type: "ERC20",
options: {
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on mainnet, checksummed
chainId: 1,
},
},
});
// true = request accepted by the wallet, not "the user clicked Add"
Things to know
truemeans only that the request was valid. Do not treat it as confirmation that the token was added.- Wallets should warn when a token's name or symbol looks like a well-known token but the address or chain does not match. This is a common phishing pattern.
- Fetching metadata from arbitrary URLs is a server-side request forgery (SSRF) risk. The spec tells wallets to allowlist schemes and ports.
- In practice, wallets such as MetaMask also accept
symbol,decimalsandimageinoptionsfor theERC20type. Those fields are not part of this spec's text. The spec recommends theERC1046type, which gets metadata from the token itself. - A related wallet method for adding networks is EIP-3085
wallet_addEthereumChain, which is Stagnant.