0

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.

Regards

1

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.

1

You should try the same as suggested by Ismael. But this will work in two cmd commands like this if you try only account = (await web3.eth.getAccounts())[3]. This will give you undefined . You should try like this

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

undefined

truffle(development) > account

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.