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?



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.


3 Answers 3


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.

  • 1
    I don't see privacy mode anymore. Has it been deleted from the latest version?
    – GGizmos
    Jun 30, 2021 at 17:47

To get current account selected in Metamask: web3.eth.accounts[0].

To make above code work with metamask, set coinbase on ganache, and then configure and use custom RPC url (provided by ganache ) in metamask.

  • web3.eth.accounts[0] Isn't that outdated.
    – faruk13
    Apr 18, 2019 at 9:14
  • I can get first account from the list of address returned from web3.eth.getAccounts() but that address and the metamask account address are not same which should be same actually, shown in the tutorial.
    – faruk13
    Apr 18, 2019 at 9:17
  • web3.eth.getAccounts() will return accounts controlled by ethereum node, whereas metamask itself is a wallet with its own addresses, which are different from addresses created on node. However you could import ethereum node addresses in metamask manually with import account option. And, web3.eth.accounts[0] is not deprecated, Metamask uses web3 version 0.20.X.
    – kherwa
    Apr 18, 2019 at 9:36
  • Doesn't this just return the first account? Not the current?
    – GN.
    Dec 13, 2020 at 7:19

For me it helped, "manually connect" the current side on Metamask. enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.