I'd like to make new account by JSON-RPC.I've checked the wiki of Ethereum, however I could not find out how to do that.

I've found call existed accounts, but it isn't what I want. eth_accounts

Could you tell me how to do this?

up vote 26 down vote accepted

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.
  • 2
    Hmm, actually it looks like the web3.js library doesn't implement personal functions, even over IPC. Give me a minute to hack something together. – Tjaden Hess Feb 16 '16 at 9:30
  • 1
    @toshikaseda I forked the web3_extended library to allow IPC connections. github.com/tjade273/web3_extended – Tjaden Hess Feb 16 '16 at 9:55
  • 1
    Thx, I'll check it! – lalala Feb 16 '16 at 9:57
  • 2
    Well, I've created a PR to merge web3_ipc into web3_extended, but there's been no reply. These tools really aren't supposed to be exposed by web3, so idk if merging them would be smart – Tjaden Hess May 24 '16 at 7:54
  • 2
    @TjadenHess how can I unlock account using private key instead of password into json rpc – Yogesh Karodiya Nov 6 '17 at 12:58

In ethereum-php/ethereum.php add

function personal_newAccount($passphase) { return $this->ether_request(__FUNCTION__, array($passphase)); }

and call it to create new account

  • btelle/ethereum-php is hopelessly outdated. – digitaldonkey Aug 10 at 11:35

From the looks of it, i think you are using testrpc of ganache to do this. If you are using python to do this. It is very simple. First you need to install web3. Type in the following in the terminal

pip install web3

(make sure you are using python 3.5 or above.) Now open python console in the terminal by typing in python in the terminal. Once you are in the python console, type in

from web3 import Web3
web3 = Web3(Web3.HTTPProvider("http://127.0.0.1:8545"))
web3.newAccount('1234')

Here '1234' is the passcode that is required to create the ethereum account. If you do not provide the passcode, you will be prompted to do so. If you are not using testrpc or ganache, you should change the HTTPProvider to some other providers as instructed here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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