I have a simple web3.js based app and like to call a method from an contract.

For this method an authenticaten is needed. I found some examples in the web using web3.eth.accounts.signTransaction But in this case, I need the private key.

Waht I need is something like web3.eth.personal.unlockAccount, which unlock the account not for an time range, but for the transaction only.

Is this possible?

2 Answers 2


You could use BatchRequests to unlock, send a transaction, and then lock your account. You can see lockAccount at the bottom of the personal section under TODO, it is implemented just not documented.

I believe that this still opens up a window of opportunity for someone else to hit the API and send a transaction that you don't want, but it is at least tiny.

I'd recommend not using your Ethereum node to handle private keys. Possibly create an intermediate proxy service if you don't trust the frontend user.


Your dApp users use a wallet like MetaMask that will do this for your dApp:


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.