И web3.eth.accounts.create, и web3.eth.personal.newAccount не работают - PullRequest
0 голосов
/ 30 января 2019

Я уже знаю, в чем разница между accounts.create() и personal.newAccount().

Моя настройка гета такова,

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

web3.eth.getBalance() работает очень хорошо.

Но оба web3.eth.accounts.create() и web3.eth.personal.newAccount() не работают.

Нет сообщений об ошибках.Просто нет ответа.

Что я могу сделать для этой ситуации?Помогите мне, пожалуйста.

Вот пример кода.

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.

1 Ответ

0 голосов
/ 30 января 2019

Я предполагаю, что вы используете web3-1.xx, если не сообщите мне.

Ответ:

web3.eth.personal.newAccount возвращает Promise<string>, вам нужно либо await, либоили .then it - документы здесь 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 () также является обещанием, поэтому

web3.eth.accounts.create()
                 .then(console.log);

надеюсь, что это поможет

...