I want to persistent metamask connection on closing the browser window. So when I connect my dapp to metamask, close the window, and open the dapp again, I don't need to connect it again. I implemented a Similar thing using web3-react but I am facing issues with thirdweb-dev/react.
Asked
Active
Viewed 102 times
0
-
Please provide enough code so others can better understand or reproduce the problem. – Community Oct 21 '22 at 15:45
1 Answers
0
I solved that by checking the MetaMask accounts length, it returns an Array of accounts.
const handleWalletConnect = async () => {
try {
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' })
setWallet(accounts[0])
} catch (e) {
console.error(e)
}
}
useEffect(() => {
window.setTimeout(() => {
if (window.ethereum._state.accounts.length > 0) handleWalletConnect()
}, 1000)
}, [])

Amir Rahimi
- 36
- 5