I am following a truffle tutorial where the individual users web3.eth.accounts to retrieve all the accounts from Ganash. However that seemed depreciated and to duplicate his results I used web3.eth.getAccounts() as you can see below. enter image description here

However a next command is ran in truffle console web3.eth.accounts[0] which presents account at position 1 (well the first account).

Ultimately, this is my problem as I cannot yet figure out how to accomplish the same in truffle 5.I have tried web3.eth.getAccounts([0]) and web3.eth.getAccounts().then(e => let firstAcc=e[0]; console.log(firstAcc)); which was suggested but neither works. Appreciate any help or guidance I could receive to assist me with this small issue.



Truffle v5 uses web3 v1 that uses promises to return values. To access the third account you have do something like this:

account = (await web3.eth.getAccounts())[3]

Now account contains the address.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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