Search code examples
javascriptethereumblockchainweb3jsgo-ethereum

Calling web3.eth.personal.unlockAccount throws error


I am on web3 1.0.0-beta.27, and I ran a private blockchain as: geth --identity "node" --nodiscover --maxpeers 0 --datadir path/to/data --networkid 123 --ws --wsport 8546 --wsorigins "*" console

Then in a app.ts file I have:

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');
});

But I get error:

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

Searching online for this issue, I should have started the geth process with --rpcapi="db,eth,net,web3,personal,web3", however adding this flag does not help, even though rpc is just a kind of ipc correct?

Furthermore, on the geth console I am able to unlock the account with

personal.unlockAccount(sender, 'password')

Solution

  • You added personal to rpcapi, but are connecting through WS. You need to add it to wsapi.

    rpc is just a kind of ipc correct?

    The 3 connection protocols are IPC-RPC, JSON-RPC, and WS-RPC. The rpc* configuration parameters are for JSON-RPC (over HTTP), not IPC/WS.