Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

I'm having an issue when running encryptKey.js - solved #69

Open
mederocc opened this issue Mar 22, 2023 · 1 comment
Open

I'm having an issue when running encryptKey.js - solved #69

mederocc opened this issue Mar 22, 2023 · 1 comment

Comments

@mederocc
Copy link

Solved.

It seems like wallet.encrypt() in file encrypt.js now expects a callback to be passed instead of the private key.

async function main() {
  const wallet = new ethers.Wallet(process.env.PRIVATE_KEY);

  const encryptedJsonKey = await wallet.encrypt(
    process.env.PRIVATE_KEY_PASSWORD,
    callback // <== previously process.env.PRIVATE_KEY
  );
  console.log(encryptedJsonKey);
  fs.writeFileSync("./.encryptedKey.json", encryptedJsonKey);
}

Callback in documentation:

function callback(progress) {
  console.log("Encrypting: " + parseInt(progress * 100) + "% complete");
}
@NaelShichida
Copy link

Thanks for this, for anyone having trouble doing this in July 2023 I believe you no longer have to pass the pirvate key since it is inferred from the "wallet"

Here is the code:

const ethers = require("ethers");
const fs = require("fs-extra");
require("dotenv").config();

async function main() {
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY);

const encryptedJsonKey = await wallet.encrypt(
process.env.PRIVATE_KEY_PASSWORD
);

console.log(encryptedJsonKey);
fs.writeFileSync("./.encryptedKey.json", encryptedJsonKey);
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants