Created
February 20, 2022 08:28
-
-
Save lex-world/06b95274c7e2914e60363a0f9eb3baf4 to your computer and use it in GitHub Desktop.
This file contains 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 detectEthereumProvider from '@metamask/detect-provider' | |
const provider = await detectEthereumProvider() | |
if (provider) { | |
console.log('Ethereum successfully detected!') | |
// From now on, this should always be true: | |
// provider === window.ethereum | |
// Access the decentralized web! | |
// Legacy providers may only have ethereum.sendAsync | |
const chainId = await provider.request({ | |
method: 'eth_chainId' | |
}) | |
} else { | |
// if the provider is not detected, detectEthereumProvider resolves to null | |
console.error('Please install MetaMask!', error) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment