0
const accounts = await web3.eth.getAccounts()
    //sets the state of the account as a part of the constructor.
console.log(accounts[0])

Id used the above code to display the account information of the user. I have tried with the Main Ethereum network and Ganache, using metamask. Unfortunately, it states the account is undefined. Please help.

  • Are you sure that metamask is connected to Ganache? How have you started Ganache? – goodvibration Jul 29 '19 at 13:47
  • @goodvibration ya it is. I connected using the local rpc of Ganache – Atul Anand Jul 29 '19 at 14:20
  • It however seems to be an issue with metamask. When I provide the rpc of ganache it gives out the address. Can you pls help me out with that? – Atul Anand Jul 29 '19 at 14:32
1

You need to execute ethereum.enable() first, see: https://metamask.github.io/metamask-docs/Advanced_Concepts/Provider_API

Alternatively you could disable the privacy mode of metamask (in settings / Security & Privacy) See https://medium.com/metamask/introducing-privacy-mode-42549d4870fa

| improve this answer | |
  • 1
    This should be posted as a comment, not as an answer. – goodvibration Jul 29 '19 at 14:08
  • No I havent. Will try. – Atul Anand Jul 29 '19 at 14:21
  • Worked like a wonder.Thanks a tonne!! – Atul Anand Jul 29 '19 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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