I'm trying to use ethers-ens which requires an ethereum account in JSON format. How can I export or generate an account.json from my metamask account? Is there another way to use ethers-ens without an account.json?

This is a sanitized example format based on account.json generated by ethers-ens:

    "address": "",
    "id": "",
    "version": ,
    "Crypto": {
        "cipher": "",
        "cipherparams": {
            "iv": ""
        "ciphertext": "",
        "kdf": "",
        "kdfparams": {
            "salt": "",
            "n": ,
            "p": ,
        "mac": ""


While MetaMask plans to add the ability to export this file format (check that link to see if it's been done yet), it currently only allows exporting the hex-encoded private key for individual accounts. That's a series of 64 characters (0-9 and A-F), which you can copy to your clipboard.

This private key string is not encrypted, and so anywhere it can be read it can be used to control its account.

The JSON file format includes the encrypted key, with some information about how it was encrypted. This makes it good for saving to your hard drive.

Once you have this private key copied, you can import it into Geth or Parity, and then export the JSON file from one of those.

| improve this answer | |

It must be a better way but here's how I did it.

Firstly it's important to understand that the mnemonic phrase could be used to generate an infinite number of private keys and the JSON Keystore format stores just one private key. That means that you'll need to do the following procedure for each private key you want to import on the Ethereum Wallet.

First you need to find the private key for a specific address:

  1. Go to MyEtherWallet.com
  2. Select the appropriated network on the upper right corner
  3. Click on 'View Wallet Info'
  4. Choose 'Mnemonic Phrase'
  5. Paste/type your mnemonic
  6. Type your password and unlock the account
  7. Select the correct derivation path. If the case of MetaMask that should be first one: m/44'/60'/0'/0
  8. Select the desired address
  9. You should see your private key under under field 'Private Key (unencrypted)'

Now that you have the private key you need to covert it to JSON Keystore file. You can do this using geth but in my case I've used a javascript library called ethereumjs-wallet as the following:

const fs = require("fs")
const wallet = require("ethereumjs-wallet")

const pk = new Buffer.from('c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3', 'hex') // replace by correct private key
const account = wallet.fromPrivateKey(pk)
const password = 'something' // will be required to unlock/sign after importing to a wallet like MyEtherWallet
const content = JSON.stringify(account.toV3(password))

// writes to a file
const address = account.getAddress().toString('hex')
const file = `UTC--${new Date().toISOString().replace(/[:]/g, '-')}--${address}`
fs.writeFileSync(file, content)

Hope somebody has a better alternative out there.

| improve this answer | |
  • Couple of small fixes to your code: 1. const wallet = require("ethereumjs-wallet").default (or else use import) 2. toV3 returns a Promise so either await it, or enclose the rest of the code in a then clause. – Traveling Tech Guy yesterday

Install the "MEW CX" Google Chrome extension, import the wallet using the MNENOMIC, and export "Keystore File (UTC/JSON)".

| improve this answer | |

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.