调用 web3.eth.personal.unlockAccount 会抛出错误

Calling web3.eth.personal.unlockAccount throws error

我在 web3 1.0.0-beta.27,我 运行 一个私有区块链作为: geth --identity "node" --nodiscover --maxpeers 0 --datadir path/to/data --networkid 123 --ws --wsport 8546 --wsorigins "*" console

然后在 app.ts 文件中我有:

import * as Web3 from 'web3';

var web3   = new Web3(new Web3.providers.WebsocketProvider('ws://localhost:8546'));

web3.eth.getAccounts().then(accounts => {
    var sender = accounts[0];
    web3.eth.personal.unlockAccount(sender, 'password');
});

但我得到错误:

Unhandled rejection Error: Returned error: The method personal_newAccount does not exist/is not available

在线搜索这个问题,我应该用 --rpcapi="db,eth,net,web3,personal,web3" 启动 geth 过程,但是添加这个标志没有帮助,即使 rpc 只是一种 ipc 正确吗?

此外,在 geth 控制台上,我可以使用

解锁帐户
personal.unlockAccount(sender, 'password')

您已将 personal 添加到 rpcapi,但正在通过 WS 进行连接。您需要将其添加到 wsapi.

rpc is just a kind of ipc correct?

三种连接协议是IPC-RPC、JSON-RPC和WS-RPC。 rpc* 配置参数用于 JSON-RPC(通过 HTTP),而不是 IPC/WS。