2
  • Code:

    var Web3 = require('web3');
    var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
    
    
    var sender = web3.eth.accounts[0];
    console.log('Sender: ' + sender);
    
    web3.personal.listAccounts;
    
  • Output:

    Sender: 0xA0A0A01
    
    
    home/ubuntuuser/node_modules/web3/lib/web3/requestmanager.js:61
        throw errors.InvalidResponse(result);
        ^
    Error: The method personal_listAccounts does not exist/is not available
    at Object.module.exports.InvalidResponse (/home/ubuntuuser/node_modules/web3/lib/web3/errors.js:38:16)
    at RequestManager.send (/home/ubuntuuser/node_modules/web3/lib/web3/requestmanager.js:61:22)
    at Personal.get [as listAccounts] (/home/ubuntuuser/node_modules/web3/lib/web3/property.js:107:62)
    at Object.<anonymous> (/home/ubuntuuser/Desktop/Ethereum/ethy.js:63:14)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    

  • Question:

From the above, commands like web3.eth.accounts[0] works fine, however web3.personal.listAccounts; doesn't. Why might that be the case?

4
  • 1
    How did you launch geth? It can be that you have missed enabling the personal api from the command line, try adding personal to the --rpcapi something like this geth --rpc --rpcapi eth,web3,net,ssh,db,debug,personal enable serveral apis.
    – Ismael
    Jul 3, 2017 at 18:21
  • @Ismael this worked! :) :) thank you so much. If you make an answer explaining that I will give it the checkmark
    – Webeng
    Jul 3, 2017 at 18:56
  • 1
    Note that this can be very unsafe; there is a reason why the personal interface isn't exposed over RPC by default. You can do this more safely over IPC ethereum.stackexchange.com/questions/1413/… Jul 3, 2017 at 19:45
  • oh thanks @TjadenHess this is really important. I'll try out the method in that post there. Would leaving the --rpc in geth --rpc also cause a security risk? or was it just the --rpcapi ...?
    – Webeng
    Jul 3, 2017 at 19:51

0

Browse other questions tagged or ask your own question.