1

I am new to Ethereum.

I am running a geth devnode.

Installed web3.

Used web3.eth.accounts.create function to create one account without any entropy and created another account by using the same command with entropy - for both these, I was given the address and private key for the accounts.

Then when I query web3.eth.getAccounts(console.log), the reply did not include the newly created accounts.

Any information on why these newly created accounts aren't listed?

On node command prompt, I did these:

Web3 = require('web3');
web3 = new Web3('localhost:8545');
web3.eth.accounts.create(); //this gave me the address and the private key for the first account
web3.eth.accounts.create("aaabbbb"); //this gave me the address and the private key for the 2nd account
web3.eth.getAccounts(console.log); //the list this gives doesn't have the two accounts I created by the above steps 

Thanks in advance

7
  • Please show your code. Commented Mar 20, 2019 at 9:59
  • On node command prompt, I did these: Web3 = require('web3'); web3 = new Web3('localhost:8545'); web3.eth.accounts.create(); //this gave me the address and the private key for the first account web3.eth.accounts.create("aaabbbb"); //this gave me the address and the private key for the 2nd account web3.eth.getAccounts(console.log); //the list this gives doesn't have the two accounts I created by the above steps
    – vasanthi
    Commented Mar 20, 2019 at 10:05
  • Each one of those function calls should run asynchronously. Are you sure that you're waiting for them to complete? Also - you mentioned what the last function call doesn't return, but how about telling us what it does return? Commented Mar 20, 2019 at 10:24
  • Thanks. Yes, I was waiting for each command to return. The last command returned the addresses of the accounts I created soon after creating the geth node using the geth command personal.newAccount() on the geth prompt. The last command web3.eth.accounts did not return the 2 new addresses that were created by web3.eth.accounts.create([entropy])
    – vasanthi
    Commented Mar 20, 2019 at 10:33
  • Again - did not return is not what I asked. I asked what it did return. Not sure how else to explain this. Commented Mar 20, 2019 at 10:53

1 Answer 1

1

web3.eth.getAccounts will only return a list of accounts controlled by node. Accounts created through web3.eth.accounts.create will not be listed here. for creating accounts on node using web3 use web3.eth.personal.newAccount()

4
  • Thanks a lot. Calling web3.eth.personal.newAccount(<password>), seems to bring up the account created when I issue web3.eth.getAccounts. Does it mean the accounts I created by web3.eth.getAccounts can't be used in creating a transaction?
    – vasanthi
    Commented Mar 20, 2019 at 12:13
  • yes, account created with web3.eth.accounts.create can also be used to create transactions, but these accounts are ephemeral accounts, where as accounts created with web3.eth.personal.newAccount persists on node(stored locally on node).
    – kherwa
    Commented Mar 20, 2019 at 12:27
  • Thank you. Using web3, I did create a transaction with those accounts that created by web3.eth.accounts.create. When I try to send the transaction, I got : Node error: {"code":-32000,"message":"invalid sender"}. In order to find out why that happened, I started looking at web3.eth.getAccounts. Any info on what I need to do in order to use the ephemeral accounts in a transaction? Thanks in advance
    – vasanthi
    Commented Mar 20, 2019 at 13:12
  • Have you signed the transaction... post your code ... that will give a better context...
    – kherwa
    Commented Mar 21, 2019 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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