Search code examples
javascriptethereumweb3js

Web3 v1 nodejs call to get Ethereum accounts via RPC call


I cannot understand how to get a listing of my accounts using the new Web3 v1 JS lib. It use to be easy: web3.eth.accounts.

Does anyone know how to get a simple listing of accounts using Web3 v1 JS lib in node?

This returns more data than just the accounts, so I'm at a loss here.

web3.eth.getAccounts().then(console.log)


Solution

  • web3.eth.getAccounts().then(function(accts) { 
        accounts = accts 
    })
    

    Accounts are then available as web3.eth.accounts use to be; so accounts[0], accounts[1], etc. are now available. I was able to resolve it using the above line of code.