Issue with getting web3 eth accounts MetaMask

0 votes

I am facing some issue with ethereum. web3.eth.accounts[0] or web3.eth.accounts is not working. When I tried console.log(web3.eth.accounts[0]), it returns undefined. But when I use console.log(web3.eth), I can see all the data in the console.

            window.addEventListener('load', function(){
                if( typeof web3 !='undefined'){
                    console.log('web3 detected');
                    web3 = new Web3(web3.currentProvider);                                    
                    alert("please install MetaMask");
Oct 12, 2018 in Blockchain by sabby
• 4,370 points

4 answers to this question.

+1 vote
Best answer

I solved problem, using:

 web3.eth.getAccounts((err, res) => {                   
answered Oct 12, 2018 by Perry
• 17,100 points

selected May 7, 2019 by Omkar
+1 vote

It is not working because web3.eth.accounts is not a list, it is a constructor. 

answered May 7, 2019 by Drake
+1 vote

If you are using web3js 1.0 then use this:

const web3 = new Web3(window.web3.currentProvider);
answered May 7, 2019 by Kriti
–1 vote

Instead of using it as a variable, try using the function:


answered May 7, 2019 by John
There's no such function

Related Questions In Blockchain

+1 vote
1 answer

Getting issues while Sending signTransaction with web3.js

The chain ID for ropsten is 3. ...READ MORE

answered Mar 28, 2018 in Blockchain by Johnathon
• 9,090 points
0 votes
1 answer
0 votes
1 answer

Why am I not getting 100 ethers in my metamask account?

Sorry that you're having this problem. To ...READ MORE

answered Jun 14, 2018 in Blockchain by Christine
• 15,830 points
0 votes
2 answers

How do I interact with a smart contract on a private network through web3.js

I found a blog that explains how ...READ MORE

answered Aug 20, 2018 in Blockchain by slayer
• 29,310 points
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,830 points
0 votes
1 answer
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,440 points
0 votes
1 answer

Çannot implement web3.eth.subscribe on Web3 version 1.0.0-beta.27

As the error suggests, pub/sub is not ...READ MORE

answered Jun 19, 2018 in Blockchain by Perry
• 17,100 points

edited Jun 19, 2018 by Perry 932 views
+4 votes
2 answers

I am unable to connect Ganache with Truffle/Npm Dev server. Pls help.

The issue is at CurrentProvider. Give the url ...READ MORE

answered Mar 26, 2018 in Blockchain by Perry
• 17,100 points

edited Oct 11, 2018 by Omkar 1,123 views