【问题标题】:Both web3.eth.accounts.create and web3.eth.personal.newAccount don't workweb3.eth.accounts.create 和 web3.eth.personal.newAccount 都不起作用
【发布时间】:2019-06-23 12:46:40
【问题描述】:

我已经知道accounts.create()personal.newAccount() 之间的区别。

我的Geth设置是这样的,

--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.

【问题讨论】:

    标签: web3 geth


    【解决方案1】:

    如果不告诉我,我假设您正在使用 web3-1.x.x。

    答案:

    web3.eth.personal.newAccount 返回一个Promise<string> 你需要await 它或.then 它 - 此处的文档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);
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2018-10-09
      • 2019-06-23
      • 2018-04-01
      • 2021-10-01
      • 1970-01-01
      • 2021-08-22
      • 2019-07-03
      • 2018-03-17
      • 2018-08-18
      相关资源
      最近更新 更多