Skip to content

Instantly share code, notes, and snippets.

@jinsley8
Last active January 10, 2023 05:36
Show Gist options
  • Save jinsley8/b4772c7733f96b78ac54a6ff87603ca9 to your computer and use it in GitHub Desktop.
Save jinsley8/b4772c7733f96b78ac54a6ff87603ca9 to your computer and use it in GitHub Desktop.
Check if MetaMask is installed on the browser in React
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