The command:
web3.eth.accounts
Returns an empty array despite Metamask having one account, how should I be retrieving the accounts in a way that will work with Mist and Metamask?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityTurns out for Metamask to do or return anything you need to access the dapp through a local or remote webserver and not through the local filesystem (file://) due to browser security restrictions.
The safest way to do it is to call asynchronously, web3.eth.getAccounts(function(err, accounts) { })
.
You will also get an empty array if the user is not signed in.
web3.eth.getAccounts(console.log)
. If the code hasn't reached that block, it makes me wonder if the page's connection was broken. Reload the page and try again?
I'm also facing same problem. My ganache was running, metamask is also running, web3 is also injected. The problem was web3.eth.accounts
and web3.eth.getAccounts().then(...)
was returning null. But after lot of searching I found that
ethereum.enable()
I run this command and one metamask popup was opened, which connected my metamask account to app.