0

I already know what is the difference between accounts.create() and personal.newAccount() .

My Geth setting is like this,

--rpcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3"

web3.eth.getBalance()runs very well.

But both web3.eth.accounts.create() and web3.eth.personal.newAccount() don't work.

No any error messages. Just no response.

What can I do for this situation? Help me please.

Here is the example code.

const Web3 = require("web3");
const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); // Geth RPC is working.
...
const password = "test1234";
const account = web3.eth.personal.newAccount(password); // not work.
console.log(account); // not work. not print anything.
TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

0

I am assuming you are using web3-1.x.x if not let me know.

Answer:

web3.eth.personal.newAccount returns a Promise<string> you need to either await it or .then it - docs here https://web3js.readthedocs.io/en/1.0/web3-eth-personal.html

const Web3 = require("web3");
const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); // Geth RPC is working.
...
const password = "test1234";
web3.eth.personal.newAccount(password)
                           .then(account => console.log(account));

web3.eth.accounts.create() is a promise as well so

web3.eth.accounts.create()
                 .then(console.log);
TylerH
  • 20,799
  • 66
  • 75
  • 101
Josh Stevens
  • 3,943
  • 1
  • 15
  • 22