MetaMask / MetaMask/metamask-extension

[Bug]: `wallet_watchAsset` adds tokens to wrong network

Open
#40,264 1 comment 0 reactions 1 assignee Claimed by @khanti42 View on GitHub
needs-triage regression-RC-13.20.0 type-bug
Dominant language
TypeScript
Stars
13.2k
Forks
5.6k
Avg merge
2d 5h
Merged PRs (30d)
451

Description

### Describe the bug

When a user calls `wallet_watchAsset` to add a token, the token is added to the network associated with the dApp’s origin (via SelectedNetworkController / getNetworkClientIdForDomain) instead of the wallet’s currently selected network. As a result, tokens can appear on the `wrong chain` (e.g. mainnet instead of a custom/testnet).

### Expected behavior

`wallet_watchAsset` should add the token to the network the user is currently viewing in MetaMask (`NetworkController.state.selectedNetworkClientId`), regardless of the dApp’s origin. This matches MetaMask Mobile, which uses `selectNetworkClientId(state)` (wallet’s selected network) and does not use a request-level `networkClientId` for watchAsset.

### Screenshots/Recordings

https://github.com/user-attachments/assets/9055c482-89b5-4262-8178-34d098127eb3

### Steps to reproduce

1. Add a custom network (e.g. Tempo testnet, chain ID `0xa5bf`) in MetaMask.
2. In MetaMask, switch to that network (ensure it is the selected network).
3. Open a dApp whose origin has a different `networkClientId` (e.g. mainnet) — e.g. [Tempo Faucet](https://docs.tempo.xyz/quickstart/faucet).
4. Trigger `wallet_watchAsset` (e.g. add ThetaUSD at `0x20C0000000000000000000000000000000000003`).
5. Accept the add-token prompt in MetaMask.
6. Observe: the token is added under mainnet (`0x1`) instead of the custom network (`0xa5bf`).

### Error messages or log output

```shell

```

### Where was this bug found?

Internal release testing

### Version

13.20.0

### Build type

None

### Browser

Chrome

### Operating system

MacOS

### Hardware wallet

_No response_

### Additional context

_No response_

### Severity

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.