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

  • Please show your code. – goodvibration Mar 20 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 Mar 20 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? – goodvibration Mar 20 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 Mar 20 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. – goodvibration Mar 20 at 10:53
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()

  • 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 Mar 20 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 Mar 20 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 Mar 20 at 13:12
  • Have you signed the transaction... post your code ... that will give a better context... – kherwa Mar 21 at 5:14

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.