'eth_accounts' unexpectedly updated accounts

I’m using web3-react library to connect MetaMask.
Current problem is after connect once and then when MetaMask locked automatically, then trying connect again, show me console error with above text.


This error does not show when first connection, only show after locked automatically and retrying connect (button clicking in my dapp, then show unlock MetaMask popup, once fill the password, connect would be success, but in browser console, it show above error )
Why this is happening and how to solve it?
What cause this error?

FYI, I use
const signature = await provider?.getSigner().signMessage(messageToSign);
to implement user authentication, above error seems because above line. but not sure.

1 Like

Hello @BlackHorse !
Welcome to MetaMask community !

What version of the web3 library are you using?
Please check it in package.json file

3 Likes

Hello, @snwlprd.eth . Thank you for your reply. I’m using
@web3-react/core”: “8.0.35-beta.0”,
@web3-react/MetaMask”: “8.0.28-beta.0”,
@web3-react/types”: “8.0.20-beta.0”,
@web3-react/url”: “8.0.25-beta.0”,
@web3-react/walletconnect”: “8.0.35-beta.0”,

2 Likes

@BlackHorse
Can you show more code, especially the provider connection sections, and the context of using signature ?

3 Likes

@snwlprd.eth Here is what I’m trying:
In the authentication hook:

const { account, provider, connector } = useWeb3React();
...
const handleSignMessage = useCallback(async () => {
    try {
      if (!account || !provider || !connector) return;
      setIsSigning(true);
      
      // Here The logic to generate messageToSign, and then next line is to get signature
      const signature = await provider?.getSigner().signMessage(messageToSign);

      ...
      // Node.js backend api call to get access token by sending signature as param. 
      // and then next  line is to store access token to localStorage
      setToken(accessToken);
   
    } catch (e) {
      console.log('error ::', e);
      setError(e);
    } finally {
      setIsSigning(false);
    }
  }, [account, provider, connector]);
2 Likes

Try rewriting your code like this.

 const signer = provider.getSigner()
 const signature = await signer.signMessage('some message');
1 Like

Same issue occurred.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.