Last active
January 10, 2023 05:36
-
-
Save jinsley8/b4772c7733f96b78ac54a6ff87603ca9 to your computer and use it in GitHub Desktop.
Check if MetaMask is installed on the browser in React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from 'react'; | |
const [isMetamaskInstalled, setIsMetamaskInstalled] = useState<boolean>(false); | |
// Check if Metamask wallet is installed and window.ethereum exists | |
useEffect(() => { | |
if (typeof (window as any)?.ethereum !== 'undefined' && (window as any)?.ethereum?.isMetaMask) { | |
setIsMetamaskInstalled(true); | |
} else { | |
setIsMetamaskInstalled(false); | |
} | |
}, []); | |
export { isMetamaskInstalled } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment