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

facing issue while connecting to MetaMask #39

Open
KrishnaVeer7712 opened this issue May 20, 2020 · 7 comments
Open

facing issue while connecting to MetaMask #39

KrishnaVeer7712 opened this issue May 20, 2020 · 7 comments

Comments

@KrishnaVeer7712
Copy link

KrishnaVeer7712 commented May 20, 2020

when I enable MetaMask in crome and setup to required accounts, localhost web page is showing loading evin i had properly setup MetaMask as shown in image.

Capture333
But when I dissabled the MetaMask, It is showing proper output with account at index 0 as shown below:
Capture444
truffle version
Truffle v5.1.26 (core: 5.1.26)
Solidity - 0.4.25 (solc-js)
Node v12.13.0
Web3.js v1.2.1
Please help me getting out of this.

@ullahwasim
Copy link

ullahwasim commented Jul 8, 2020

  1. Add window.ethereum.enable(); after line 16(web3 = new Web3(web3.currentProvider);) in \src\js\app.js file
  2. Connect Metamask.
  3. Refresh Page

@Maniddarky
Copy link

Even after adding window.ethereum.enable() im getting the same Page with 'Loading....'

@vasvi-sood
Copy link

I'm getting the same error. Please help somebody!

@introkun
Copy link

introkun commented Jan 5, 2021

Please update function initWeb3 in the app.js with the following:

  initWeb3: function() {
    if (typeof web3 !== 'undefined') {
      // If a web3 instance is already provided by Meta Mask.
      const ethEnabled = () => {
        if (window.ethereum) {
          window.web3 = new Web3(window.ethereum);
          window.ethereum.enable();
          return true;
        }
        return false;
      }
      if (!ethEnabled()) {
        alert("Please install an Ethereum-compatible browser or extension like MetaMask to use this dApp!");
      }
      web3 = window.web3;
      App.web3Provider = web3.currentProvider;
    } else {
      // Specify default instance if no web3 instance provided
      App.web3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
      web3 = new Web3(App.web3Provider);
    }
    return App.initContract();
  },

@introkun
Copy link

introkun commented Jan 5, 2021

@vasvi-sood could you please try my solution?

@vasvi-sood
Copy link

It is working with your code thanks. But the actual problem was that I needed to refresh the page, because metamask didn't connect automatically.

@gc2000
Copy link

gc2000 commented Jun 6, 2021

Thanks!

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

6 participants