0

I'm playing about with web3js@1.0.0-beta.55 and I'm setting an HttpProvider on Ganache for my web3 instance:

this.web3Instance = new Web3(new Web3.providers.HttpProvider(environment.ethereum.provider));

I've noticed that if I call this.web3Instance.eth.getAccounts() it returns the Ganache accounts, as I would've expected. However, if I create a new wallet using this.web3Instance.eth.accounts.wallet.create(1); and then call getAccounts() again, it returns the address from the newly created wallet file, and not the accounts on my Ethereum node (i.e. Ganache).

I fail to understand why - any insight is appreciated!

0

Apologies - I could've sworn I checked the documentation on this, of which there is a very clear explanation. My mistake.

From the web3js docs for:

web3.eth.getAccounts([callback]):

Will return a list of the unlocked accounts in the Web3 wallet or it will return the accounts from the currently connected node.

This means you can add accounts with web3.eth.accounts.create() and you will get them returned here.

Although it specifies this behaviour for web3.eth.accounts.create() the same applies for web3.eth.accounts.load() and possibly other functions.

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.