0

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
1

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

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

Web3.providers.HttpProvider("http://localhost:8545");
const web3 = new Web3(web3Provider);
const getAccount = async () => {
   const accounts = await web3.eth.getAccounts();
   console.log(accounts);
};
getAccount();
-1

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

  • It displays on the account which that particular node controls not All accounts on the blockchain. – logeekal Jun 20 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.