I have a a JS file running on NodeJS on multiple devices which interact to each other, trying to write data on the Blockchain and send transactions. The problem is that every time I have to manually insert the password. I have been using personal.unlockAccount in the client console but this doesn't really solve the situation...

I am trying to develop a micro-electricity-market where multiple autonomous transactions are sent every 15 minutes, I can't stay in front of the screen all the time.

Is there any way to achieve what i would like to do?

Thanks in advance

  • Not sure about Parity, but Go-Ethereu unlockAccount takes a second argument that is time how long it keeps the account unlocked. Commented Apr 4, 2017 at 19:50

2 Answers 2


If you have the personal API enabled on your node, you can interact with it with web3 just like you would via the console.

If I'm automating something, I generally configure the service to run as an isolated user on my system. Then, I'll put the password for the account the user interacts with in a file in the user's home directory (or other location), and change the permissions to be readable only by that user.

Then I'll use a wrapper like the following to allow me to easily unlock an account, send a transaction (or set of transactions), and then re-lock the account:

function whileUnlocked(web3, account, pwfile, task) {
  return readFile(pwfile, 'utf8')
    .then(function(pw) {
      return web3.personal.unlockAccount(account, pw.trim())
        .then(function() {
          return web3.personal.lockAccount(account)

Note that this requires a modified version of web3 that's been extended to use Promises, since it simplifies this flow.

This could probably be improved by making the final then a finally, to always lock the account, regardless of whether or not the task fails.

The important bits for your uses: you'd want to call web3.personal.unlockAccount, pass it a callback that does whatever you need to do while the transaction is unlocked, then call web3.personal.lockAccount when you're done.


We have used in the pass ConsenSys' hooked-web3-provider (It is now deprecated, they point to a similar project https://github.com/ethjs/ethjs-provider-signer). That way we have a service which will sign transactions without exposing the privatekey, for example we can have a hardware key.

Our problem with personal.unlockAccount is while your account is unlocked in your node can sign any transaction. So you have a tiny window of time where your node can be attacked by a malicious third party.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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