forked from PatrickAlphaC/ethers-simple-storage-fcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encryptKey.js
26 lines (23 loc) · 811 Bytes
/
encryptKey.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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,
process.env.PRIVATE_KEY
)
// In later version (^6.2.3 as of this commit) of etherjs, PRIVATE_KEY is inferred from wallet, so there is no need to
// pass private key again.
// const encryptedJsonKey = await wallet.encrypt(
// process.env.PRIVATE_KEY_PASSWORD,
// )
console.log(encryptedJsonKey)
fs.writeFileSync("./.encryptedKey.json", encryptedJsonKey)
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})