web3 accounts coming undefined

0 votes

Hi Sir,

Is it the correct way to access web 3 accounts (trying many ways ) but accounts coming undefined

web3.eth.getAccounts(function(error, accounts) {

if (error) {




// get first (base) account

// var account = accounts[0];


please suggest correct latest way that should work

Jun 8 in Blockchain by gaurav
• 120 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Hi @gaurav!

To access all the accounts, you can use this code:

web3.eth.getAccounts().then(e => console.log(e));

And to get the first account, you can use this:

web3.eth.getAccounts().then(e => let firstAcc=e[0]; console.log(firstAcc));

answered Jun 10 by Ritvik

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,070 points
+1 vote
1 answer
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
• 16,450 points

edited Jun 19, 2018 by Perry 222 views
0 votes
1 answer

How to set web3 solidity variable value?

The setLog transaction has not yet been mined by ...READ MORE

answered Jul 6, 2018 in Blockchain by Christine
• 15,790 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,790 points
0 votes
1 answer
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 66,910 points
0 votes
4 answers

Issue with getting web3.eth.accounts (MetaMask)

I solved problem, using: web3.eth.getAccounts((err, res) => ...READ MORE

answered Oct 12, 2018 in Blockchain by Perry
• 16,450 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.