我在 web3 1.0.0-beta.27
上,我运行了一个私有(private)区 block 链:
geth --identity“节点”--nodiscover --maxpeers 0 --datadir路径/到/数据--networkid 123 --ws --wsport 8546 --wsorigins“*”控制台
然后在 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?
这 3 种连接协议(protocol)是 IPC-RPC、JSON-RPC 和 WS-RPC。 rpc*
配置参数适用于 JSON-RPC(通过 HTTP),而不是 IPC/WS。
关于javascript - 调用 web3.eth.personal.unlockAccount 会抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48268026/