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?
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?
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
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.
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.
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
personal
, admin
and miner
APIs via a standard web3.js interface.personal
functions, even over IPC. Give me a minute to hack something together.
Commented
Feb 16, 2016 at 9:30
In ethereum-php/ethereum.php add
function personal_newAccount($passphase)
{
return $this->ether_request(__FUNCTION__, array($passphase));
}
and call it to create new account
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