After initiating testrpc,

App.web3Provider = new web3.providers.HttpProvider("http://localhost:8545");  
web3 = new Web3(App.web3Provider);          

it is displaying 10 accounts, but when accessing web3.eth.accounts/web3.eth.getAccounts, it returns only the first account. What went wrong?

  • web3.eth.accounts[0] thru web3.eth.accounts[9] should work just fine. – goodvibration May 2 '18 at 8:15

try in this way and run for example with 'node file_name.js'

const Web3 = require('web3');
const web3Provider = new 

const web3 = new Web3(web3Provider);
const getAccount = async () => {
   const accounts = await web3.eth.getAccounts();
| improve this answer | |

you shoud use web3.eth.accounts instead, to get the list of all accounts. Take a look at the documentation: https://github.com/ethereum/wiki/wiki/JavaScript-API#web3eth

| improve this answer | |
  • It displays on the account which that particular node controls not All accounts on the blockchain. – logeekal Jun 20 '19 at 8:38

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.