0

I'm trying to get accounts like that:

window.web3.eth.getAccounts( (error, accounts) => { console.log(accounts, error) } );

but it keeps returning an empty array. I'm running Ganache and I can see the accounts on MetaMask, but I cannot access them from my frontend Web3 Angular app. This used to work and now doesn't. I didn't change anything. And idea on how to fix this?

Also web3.eth.accounts returns an error Error: Invalid JSON RPC response:

This is how I init my web3:

if (typeof window.web3 !== 'undefined') {
      this.web3Provider = window.web3.currentProvider;
    } else {
      this.web3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
    }

    window.web3 = new Web3(this.web3Provider);
  • Do you have metamask connected to the local node ? – strangethingspy Jul 14 at 7:26
  • have you tried chang the port is 8545? ganache runs on this by default – Samuel Dare Jul 15 at 3:17

Your Answer

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

Browse other questions tagged or ask your own question.