Not able to create accounts for Private Ethereum Blockchain using Geth and Web3 API

2.3k views Asked by At

I am unable to create accounts for Private Ethereum Blockchain using Geth and Web3 API. personal.newAccount(passwd) is not working for me. Please explain how to create account using above command. And also, I am unable to install "ethereumjs-accounts".

2

There are 2 answers

0
q9f On

If you try to search the internet why the "geth json rpc personal api" is not working, you will find an excellent answer on Ethereum Stack Exchange which I'd like to quote in full:

First, a note on safety:

You should not make the personal API available over RPC

If you are on a local, trusted machine, you should use IPC instead of RPC. Otherwise, anyone who can connect to your node via RPC can try to brute-force your passwords and steal your Ether.

All administrative APIs are available by default over IPC, so no need to use any flags with geth

To connect via IPC:

Install my library: npm install web3_extended

var web3_extended = require('web3_extended');

var options = {
  host: '/home/user/.ethereum/geth.ipc',
  ipc:true,
  personal: true, 
  admin: false,
  debug: false
};

var web3 = web3_extended.create(options);

web3.personal.newAccount("password",function(error,result){
    if(!error){
        console.log(result);
    }
});

Replace the host variable with the proper path for your system.

Note: All requests via IPC must be asynchronous.


Some Alternatives:

I don't know why you want to create new accounts via web3, but it's likely not the best way to do what you're trying to achieve. It is much safer and more modular to use a hooked web3 provider with a client-side light wallet or to simply use the Mist browser which handles all accounts for you.

Now for the technique (don't do this)

You need to enable the personal API over RPC. Do this by starting geth with

geth --rpc --rpcapi "db,eth,net,web3,personal"

Then you can use the personal_newAccount method via RPC. It's not implemented in web3.js, so you need to manually issue the RPC request. For example with curl:

curl -X POST --data '{"jsonrpc":"2.0","method":"personal_newAccount","params":["password"],"id":1}' localhost:8545

creates a new account with password password and returns the address:

{"id":1,"jsonrpc":"2.0","result":"0x05ca0ddf7e7506672f745b2b567f1d33b7b55f4f"} There is some basic documentation

Alternatively: Use the unofficial extended web3.js

  • this allows you to use the personal, admin and miner APIs via a standard web3.js interface.

Published on Feb 16 at 8:34 and released under terms of CC BY-SA 3.0 by Tjaden Hess.

0
Divya Galla On

The command must be personal.newAccount()

Then the console asks for passphrase, give your required password then it again asks for confirmation.

An output in the form of Address("0x----------------------------") will appear.It is 1 account/address for your private network.