Search code examples
node.jsherokuethereumweb3js

dApp : Web3.eth.getCoinbase(function(err, account) not displaying my connected rinkeby account from metamask


I have a dApp that works on my local Ganache network but not on Rinkeby deployed on Heroku

I have this code in App.js :

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

But it this is what i get : Your Account: null

here is the file : https://github.com/Louvivien/filmproductiondapp/blob/master/src/js/app.js

Do you know what i can do ?


Solution

  • Metamask doesnt support web3.eth.getCoinbase() as it is a light client https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#dizzy-all-async---think-of-metamask-as-a-light-client

    web3.eth.getCoinbase() returns the account that your mining rewards go to.

    web3.eth.getAccounts()[0] returns the first account you created (index 0)

    Try: var account = web3.eth.getAccounts()[0];