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) {

console.error(error);

}

console.log(web3.eth.getAccounts);

// get first (base) account

// var account = accounts[0];

==============================

please suggest correct latest way that should work

Jun 9, 2019 in Blockchain by gaurav
• 120 points
2,267 views

2 answers to this question.

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, 2019 by Ritvik
0 votes
Try this :  web3.eth.getAccounts()
answered Jul 23, 2020 by Manas
• 150 points

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
3,891 views
+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
• 17,100 points

edited Jun 19, 2018 by Perry 2,049 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
2,160 views
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
1,946 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,470 views
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
• 69,220 points
1,487 views
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
• 17,100 points
5,467 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP