Open mederocc opened 1 year ago
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); }
Solved.
It seems like wallet.encrypt() in file encrypt.js now expects a callback to be passed instead of the private key.
Callback in documentation: