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 8 in Blockchain by gaurav
• 120 points
63 views

1 answer 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 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,080 points
465 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,020 points

edited Jun 19, 2018 by Perry 301 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
138 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
155 views
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
• 67,620 points
88 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,020 points
990 views