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.
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”,
@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]);