I have my public & private key (generated with MyEtherWallet), however, I forgot to create a keystore file, which would make my online access to the wallet a bit safer if I'm correct.

I got to install geth.exe on my offline computer, and

geth account import e:\rawprivatekey.txt

works, but only returns the public address. I can't seem to get it to regenerate a keystore file! Does anyone know how to do that?

3 Answers 3


When you import a key in geth it automatically creates a json wallet.

You can list existing wallets with geth account list.

A list should be like this:

Account #3: {59cc3d2701a69e2f006a47e412092d1274f81d58} keystore:///home/ubuntu/.ethereum/keystore/UTC--2018-01-28T05-19-52.363512148Z--59cc3d2701a69e2f006a47e412092d1274f81d58

The file pointed by the keystore is your json wallet you can copy and rename to some other place.

  • hmm... I only get a list of 3 (same) addresses in the parantheses, but no keystore information along with it.. I have to add that I'm offline and using Windows. Maybe the Windows version of geth.exe is different.
    – richey
    Commented Jan 28, 2018 at 23:04
  • Cool. But the command to import the private key is missing.
    – Martin
    Commented May 12, 2023 at 12:19
  • 1
    @Martin I haven't used geth in a while. It will be better to ask a new question if you haven't found the answer yet.
    – Ismael
    Commented May 12, 2023 at 14:19
  • I did find the answer in the end. You have to put the private key into a file and import it just like the OP said. Between the two you where correct. What confused me is the need to put the relatively short private key into a file instead of passing it on the command line.
    – Martin
    Commented May 17, 2023 at 14:29

With Web3.js

var Web3 = require('web3');
var web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546');
var JsonWallet = web3.eth.accounts.encrypt(privateKey, password);
  • 1
    isn't the private key communicated to the remote node? Commented Oct 30, 2021 at 6:47

If you want to generate keystore file and you have a private key, you can use web3.py (^4.0.0b6).

There is a module called Account and in this module there is a method called encrypt.

Account.encrypt(private_key, password)

Creates a dictionary containing your private key, encrypted by the supplied password. If you want to create a keyfile recognized by Ethereum clients like geth and parity: encode this dictionary with json.dumps() and save it to disk where your client keeps key files.


Yes, web3.js doesn't have it, but web3.py does

  • ok, I can install python for it, but where to find web3.py? (sorry, noob here)
    – richey
    Commented Jan 26, 2018 at 1:33
  • web3.py docs Quickstart. Commented Jan 26, 2018 at 1:35
  • I, personally, use PyCharm, so I just go Settings > Project Interpreter > Install > web3 Commented Jan 26, 2018 at 1:36
  • sorry, I can't figure it out. I have installed PyCharm on my offline computer now (the point I want to regenerate the keyfile is to avoid being forced to enter my private key in an online browser!), but web3.py isn't found that way. Guess it has to be loaded over the Internet (which it is offline from in my case). Can I manually add it somehow, or is there another method to regenerate the keystore file from the private key?
    – richey
    Commented Jan 27, 2018 at 1:43
  • I’m afraid there are no other methods to recover keystore file. Commented Jan 27, 2018 at 9:58

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.