Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to detect if MetaMask is installed? #1158

Closed
miguelmota opened this issue Mar 1, 2017 · 5 comments
Closed

Question: How to detect if MetaMask is installed? #1158

miguelmota opened this issue Mar 1, 2017 · 5 comments

Comments

@miguelmota
Copy link

is there a global variable or local storage item to check if metamask is installed?

@Zvezdin
Copy link

Zvezdin commented Mar 1, 2017

The way I'm doing is simply checking in my frontend js this:
if(typeof web3 == "undefined")

However, since metamask may not be able to inject web3 in time for app load, it's best to set a timeout with a callback checking this 1-3-ish seconds prior to loading.

@danfinlay
Copy link
Contributor

Rather than set a timer, we recommend waiting for the load event: https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#partly_sunny-web3---ethereum-browser-environment-check

@danfinlay
Copy link
Contributor

Also: web3.currentProvider.isMetaMask === true.

@aghiugan
Copy link

Maybe there is a trick to it, but for me this is still not working... No error in the console, nothing absolute nothing. I am using Chrome Version 64.0.3282.186 (Official Build) (64-bit) on ArchLinux. Metamask is pointed to a private Ethereum blockchain neteork and it is showing correctly balances for few accounts I have defined at creation time inside the network.

Here it is the code I am using. Needless to say I am extremely frustrated for getting stuck at such a simple step. Please note: in other contexts (e.g. wallet.ethereum.org) this seems to work as expected. Help would be highly appreciated.

function onLoad() {

if (typeof web3 !== 'undefined') {
// Use Mist/MetaMask's provider
web3js = new Web3(web3.currentProvider);
console.log("Using Metamask/Mist WEB3 provider")
} else {
alert('MetaMask not loaded ?!?')
return
}

}

@danfinlay
Copy link
Contributor

@aghiugan please open a new issue to discuss this problem. You might also get good community help by posting on stackexchange.

It looks like you're doing things right, so the more reproduction details you can provide, the better. Maybe worth creating a full reproduction github repository for people to try reproducing with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants