0

I tried to see all address using

web3.eth.getAccounts()

It's run perfectly. Next I tried to see the first address using

web3.eth.getAccounts().then(function(accounts) {return accounts[0]})

It's also worked well. But now I want to use this address according to their index.

when I use getAccounts[0]or getAccounts[1] sometimes it's work, sometimes not.

So is there any specific way to use those address using index?

  • Well, there is no getAccounts array (or object) anywhere, so using it with [] is obviously not going to work. This has nothing to do with Ethereum BTW, it is a simple Javascript matter. You can't take a function and expect it to "behave like an array"! – goodvibration Jul 21 at 15:58
  • 1
    yeah I understand. By the way it's solved. simple just using accounts = await web3.eth.getAccounts().. After that I'm able to see addresses using accounts[0]/accounts[1] – tithidey Jul 21 at 16:23
0

If i understand correctly you want to use the web3.eth.gethAccounts() method with an index based on which account you want to return.

Reading the documentation at https://web3js.readthedocs.io/en/v1.2.7/web3-eth.html#getaccounts the only parameter accepted by the method is the [callback] function so i think that you cannot use the index as an input parameter.

Hope this helps.

| improve this answer | |

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.