Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError on window.ethereum.on('accountsChanged', ...) #3659

Closed
DotCoyote opened this issue Jul 27, 2020 · 2 comments · Fixed by #3660
Closed

TypeError on window.ethereum.on('accountsChanged', ...) #3659

DotCoyote opened this issue Jul 27, 2020 · 2 comments · Fixed by #3660
Labels
1.x 1.0 related issues Bug Addressing a bug

Comments

@DotCoyote
Copy link

Expected behavior

The callback function from window.ethereum.on('accountsChanged', callbackFunction) is emitted without errors.

Actual behavior

The callback-function is emitted correctly, but the devTools console throws an error:

Uncaught TypeError: Cannot read property 'subscription' of undefined
    at t.exports.data (index.js?176c:105)
    at u (inpage.js:1)
    at t.exports.a.emit (inpage.js:1)
    at a.<anonymous> (inpage.js:1)
    at u (inpage.js:1)
    at a.emit (inpage.js:1)
    at inpage.js:1
    at l.write [as _write] (inpage.js:1)
    at b (inpage.js:1)
    at inpage.js:1

Going into index.js?176c:105 shows

if (result.method && _this.subscriptions.has(result.params.subscription)) {

and result only holds

{
  "method": "wallet_accountsChanged",
  "result": [
    "0x88257xxxxxxxx"
  ]
}

Steps to reproduce the behavior

  1. Create an app using ethereum and web3.js
  2. Add a method for window.ethereum.on('accountsChanged', handleAccountsChanged);
  3. Change accounts in MetaMask with the app open
  4. See the error in the console

Logs

Environment

Node: 14.4.0
npm: 6.14.5
web3.js: 1.2.11
macOS: 10.15.5
Chrome 84.0.4147.89
MetaMask 8.0.5
Chain: trufflesuite/ganache-cli:v6.9.1

@GregTheGreek
Copy link
Contributor

GregTheGreek commented Jul 27, 2020

Thank you for the report! This might be related to #3651, will investigate

@GregTheGreek GregTheGreek added 1.x 1.0 related issues Investigate labels Jul 27, 2020
@ryanio
Copy link
Collaborator

ryanio commented Jul 27, 2020

hey @DotCoyote thanks for reporting. i was able to recreate this with a test dapp.

it looks like now that metamask is sending this new event down the pipe (wallet_accountsChanged) the web3.js code is failing in that place since it is not expecting an event without a subscription property. We would just need to add some additional checks in that if statement, which i will open a pr for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants