How do you detect when a MetaMask user disconnects their wallet from your dapp? I see there is a disconnect event, but this is a for disconnecting from RPC - I want to know when the user has explicitly disconnected their wallet.

2 Answers 2


Use the accountschanged event.

ethereum.on('accountsChanged', handler: (accounts: Array<string>) => void);

Verify if has any account.

ex: the accounts variable return an array, if has any account on array your dapp is conneted.

Use this code bellow:

const accounts = await ethereum.request({ method: "eth_accounts" });
const isConnected = !!accounts.length;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.