OneKeyHQ / OneKeyHQ/app-monorepo
[BUG]: wallet_addEthereumChain throws error: Error JSON PRC response: the method wallet_addEthereumChain does not exist/is not available
- Dominant language
- TypeScript
- Stars
- 2.4k
- Forks
- 533
- Avg merge
- 21h 55m
- Merged PRs (30d)
- 497
Description
**Prerequisites**
Please answer the following questions for yourself before submitting an issue. **YOU MAY DELETE THE PREREQUISITES SECTION.**
- [x] I checked to make sure that this issue has not already been filed
- [ ] I've asked for help in the [OneKey Discord](https://discord.com/invite/onekey) before filing this issue.
**Describe the bug**
`wallet_addEthereumChain` does not seem to work any more.
Example code:
```js
window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: '0x64',
chainName: 'Gnosis Chain',
nativeCurrency: {
name: 'xDAI',
symbol: 'xDAI',
decimals: 18
},
rpcUrls: ['https://rpc.gnosischain.com/'],
blockExplorerUrls: ['https://gnosisscan.io/']
}]
});
```
Error:
```
{
"name": "Error",
"message": "Error JSON PRC response: the method wallet_addEthereumChain does not exist/is not available",
"stack": "Error: Error JSON PRC response: the method wallet_addEthereumChain does not exist/is not available\n at parseRPCResponse (chrome-extension://jnmbobjmhlngoefaiojfljckilhhlhcj/background.bundle.js:8:3585179)\n at chrome-extension://jnmbobjmhlngoefaiojfljckilhhlhcj/background.bundle.js:8:1453930\n at Array.map ()\n at ServiceDApp. (chrome-extension://jnmbobjmhlngoefaiojfljckilhhlhcj/background.bundle.js:8:1453890)\n at Generator.next ()\n at asyncGeneratorStep (chrome-extension://jnmbobjmhlngoefaiojfljckilhhlhcj/background.bundle.js:8:11373261)\n at _next (chrome-extension://jnmbobjmhlngoefaiojfljckilhhlhcj/background.bundle.js:8:11373506)"
}
```
**To Reproduce**
Go to console and execute the above code or [the sample code in your repo](https://github.com/OneKeyHQ/test-dapp/blob/843c891524b90b9f3ce777cf3c948760b5090747/src/index.js#L287-L298).
**Expected behavior**
This will prompt the "Add chain to wallet" window to appear.
**Screenshots**
The video below demonstrates me: 1) successfully using the same code to bring up Rainbow Wallet; 2) attempting to use the same code but failing to bring up OneKey Wallet.
https://github.com/user-attachments/assets/8f571764-bc6b-4dbb-b53a-9c7530f551c9
**Desktop (please complete the following information):**
- OS: macOS
- Browser: arc
- Version: latest
**Additional context**
I have just tested the Chrome extension. Some users are reporting that they are unable to do the same in the app too.
---
edit: I was trying to make a PR to fix this but found [this endpoint](https://github.com/OneKeyHQ/app-monorepo/blob/a95239e597e2fffeb4dc342e1384b6ba568ead41/packages/kit-bg/src/services/ServiceDApp.ts#L936) is not open source? Btw, you should definitely fix the disturbing `PRC` typo.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.