Web3.js – Fixing Metamask Not Returning Current Account Address with Ganache

ganachemetamaskweb3js

How to return the address of my current account from Metamask? I have tried with web3.eth.getCoinbase() but this and metamask has two different address.

web3.eth.getCoinbase() returns me the first account from the list of accounts provided by Ganache.

What I need to do to resolve this?

Thanks

P.S.:

I am following the tutorial from here and 2019 updated Github code is here.

The below code is the problem:

web3.eth.getCoinbase(function(err, account) {
      if (err === null) {
        App.account = account;
        $("#accountAddress").html("Your Account: " + account);
      }
    });

It returns null even if I have address of my account in metamask and yes I have imported an account given by Ganache onto Metamask.

Best Answer

If you switch off the privacy mode, which is under security and privacy in the metamask settings. Then refresh the page, that should display your current account address.

Related Topic