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_Passwd,
process.env.Private_Key
);
console.log(encryptedJsonKey);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
运行时报错
Error: progressCb should be function
at scryptInit (/home/devcontainers/hh-fcc/node_modules/@noble/hashes/scrypt.js:110:15)
at scryptAsync (/home/devcontainers/hh-fcc/node_modules/@noble/hashes/scrypt.js:199:84)
at _scryptAsync (/home/devcontainers/hh-fcc/node_modules/ethers/lib.commonjs/crypto/scrypt.js:8:43)
at scrypt (/home/devcontainers/hh-fcc/node_modules/ethers/lib.commonjs/crypto/scrypt.js:55:42)
at encryptKeystoreJson (/home/devcontainers/hh-fcc/node_modules/ethers/lib.commonjs/wallet/json-keystore.js:291:45)
at Wallet.encrypt (/home/devcontainers/hh-fcc/node_modules/ethers/lib.commonjs/wallet/wallet.js:48:65)
at main (/home/devcontainers/hh-fcc/hello.js:6:43)
at Object.<anonymous> (/home/devcontainers/hh-fcc/hello.js:13:1)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
devcontainers@LAPTOP-9BK8E3RN:~/hh-fcc$ node hello.js
因为跟着chainlink视频课学习,版本有所不同
const encryptedJsonKey = await wallet.encrypt(
process.env.Private_Passwd,
process.env.Private_Key
);
// 将其改为
const encryptedJsonKey = await wallet.encrypt(
process.env.Private_Passwd,
);
//即可