11

Using web3 under nodejs I suddenly want to unlock my account before calling a DAO contract function:

var Web3 = require('./node_modules/web3/lib/web3');

// dont override global variable
if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') {
   window.Web3 = Web3;
}

module.exports = Web3;

var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));

var accounts = web3.eth.accounts;
web3.personal.unlockAccount(accounts[0], "mypassword", 2);
console.log("yay")

But then I get this error:

/home/andres/Documents/Code/Crypto/ethWithdrawer/node_modules/web3/lib/web3/requestmanager.js:61
        throw errors.InvalidResponse(result);
        ^

Error: The method personal_unlockAccount does not exist/is not available
    at Object.module.exports.InvalidResponse (/home/andres/Documents/Code/Crypto/ethWithdrawer/node_modules/web3/lib/web3/errors.js:35:16)
    at RequestManager.send (/hhome/andres/Documents/Code/Crypto/ethWithdrawer/node_modules/web3/lib/web3/requestmanager.js:61:22)
    at Personal.send [as unlockAccount] (/home/andres/Documents/Code/Crypto/ethWithdrawer/node_modules/web3/lib/web3/method.js:145:58)
    at Object.<anonymous> (/hhome/andres/Documents/Code/Crypto/ethWithdrawer/approver_test.js:77:15)
    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)

Or this other error in other box:

/home/user/Code/Crypto/ethWithdrawer/node_modules/web3/lib/web3/requestmanager.js:61
throw errors.InvalidResponse(result);
^

Error: personal_unlockAccount method not implemented
at Object.module.exports.InvalidResponse (/home/user/Code/Crypto/ethWithdrawer/node_modules/web3/lib/web3/errors.js:35:16)
at RequestManager.send (/home/user/Code/Crypto/ethWithdrawer/node_modules/web3/lib/web3/requestmanager.js:61:22)
at Personal.send [as unlockAccount] (/home/user/Code/Dao/ethWithdrawer/node_modules/web3/lib/web3/method.js:145:58)
at /home/user/Code/Crypto/ethWithdrawer/web3caller.js:33:19
at Array.forEach (native)
at Object.<anonymous> (/home/user/Code/Crypto/ethWithdrawer/web3caller.js:23:10)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)

What's the problem? The function is there, I can see it by doing console.log(web3.personal).

3
  • how are you calling it? should be something like web3.personal.unlockAccount(web3.eth.accounts[0]) (no underscore) – SCBuergel May 17 '16 at 11:17
  • yes exactly like that – knocte May 17 '16 at 11:42
  • @Sebastian added code – knocte May 17 '16 at 11:45
18

I assume that you are attempting to connect to a geth node. It might be that this node does not have the personal management API loaded which you could specify while starting

geth --rpcapi eth,web3,personal --rpc

as described. Please take care, everyone with (local) access to your machine could now mess with your accounts, therefore this is disabled by default.

6
  • thanks for the warning, but geth --rpc by default only allows incoming connections from 127.0.0.1, right? – knocte May 18 '16 at 1:49
  • That is correct but the personal part of the API is just not exposed and not "visible" in the browser. – SCBuergel May 18 '16 at 8:18
  • in the browser? what browser? sorry, I'm completely lost now – knocte May 18 '16 at 8:20
  • You're trying to access an Ethereum node via RPC API from node.js (sorry not yet in the browser). But by default your geth node does not allow access for everything that's personal hence you have to specifically enable that when starting geth. – SCBuergel May 18 '16 at 8:24
  • why do you mention that again? I know that from your S.O. answer :) my point is, as I'll never allow other addresses than 127.0.0.1, I'm safe by including personal in the --rpcapi argument – knocte May 18 '16 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.