Web3.js: How can I create account in geth rpc by web3.personal.newAccount or web3.eth.accounts.create?

Created on 7 Feb 2018  路  10Comments  路  Source: ChainSafe/web3.js

When I use 0.19.0 version of web3, I can create account with web3.personal.newAccount , it appears in ipc and I can check it in geth by "geth account list". But then I can't get private key and balance in my app,only address. Lib web3-eth-accounts does not work in web3 v.0.19.0, bur I can use it in v.1.0 beta29. I can create account and get all information about it, but it doesn't post in ipc then. The task is to create a new account and get all information about it in nodejs express app.
Can you help me with this problem?
I start geth with geth --rpc --rpccorsdomain="" --rpcapi db,eth,net,web3,personal,web or geth --rpcapi "db,eth,net,web3,personal" --ws --wsaddr "localhost" --wsport "8545" --wsorigins "" --identity "MyTestNode" --datadir "./data" --testnet --fast

Most helpful comment

@froid1911 That returns a public address. What about the private key?

All 10 comments

with newAccount. eth.accounts.create creates a Javascript Wallet.

Did anyone get a solution?

web3.eth.personal.newAccount(password, [callback])
Creates a new account.

=> as already said. Pls close ticket

@froid1911 That returns a public address. What about the private key?

@fedecryto you can do that with web3.eth.accounts.create in web3.js 1.0 http://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#create

@iurimatias a bit off topic here, but in 1.0 I do like the web3.eth.accounts.create but in 1.0 there is no web3.personal which means no unlockAccount, so how do you unlock account in the new web3 1.0?

web3.eth.personal stores the account on the node. (with rpc personal)
web3.eth.accounts returns a newly generated account with pub and priv key.

links:
https://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#create
https://web3js.readthedocs.io/en/1.0/web3-eth-personal.html#newaccount

@froid1911

So in 0.20.x of web3 I can just unlock the account then call methods on my contract. But with 1.0.0 of web3 do I use web3.eth.accounts.signTransaction and then in the callback call the method on my contract? The docs are not very clear on this. Thanks for the info.

Also with web3 still in a beta version is it recommended for production apps?

0.20.x does not support browser wallets. With 0.20.x the accounts are always created on the node. Therefore you can unlock the account and sign transactions on the node.
With 1.0.0 you can also create browserwallets (web3.eth.accounts) and wallets which are stored on the node (web3.eth.personal).
i use web3 1.0.0 for all my projects, but i build only pocs and prototypes.

If we use 'web3.eth.personal.newAccount()' or 'web3.eth.personal.newAccount()' then it will create an account on the node, we can unlock that account to use it for making transactions.

But the problem is that when we restart our blockchain it will remove the new account from the node. Can we again add that new account in the node? I am really stuck in this. If someone could help me out, I will highly appreciate that.

Was this page helpful?
0 / 5 - 0 ratings