PatrickAlphaC / ethers-simple-storage-fcc

88 stars 125 forks source link

TypeError: ethers.Wallet.fromEncryptedJsonSync is not a constructor #78

Closed gracecampo closed 1 year ago

gracecampo commented 1 year ago

When I use the encrypted private key to create a wallet, it prompts me "ethers.Wallet.fromEncryptedJsonSync is not a constructor" Error message:

Debugger attached.
TypeError: ethers.Wallet.fromEncryptedJsonSync is not a constructor
    at main (D:\project\ethers-simple-storage-fcc\deploy.js:9:18)
    at Object.<anonymous> (D:\project\ethers-simple-storage-fcc\deploy.js:27:1)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

my code

 const provider =new ethers.JsonRpcProvider(process.env.RPC_URL)
    // const wallet = new ethers.Wallet(process.env.PRIVATE_KEY,provider);
    const encryptedJson = fs.readFileSync("./.encryptedKey.json", "utf8");
    let wallet = new ethers.Wallet.fromEncryptedJsonSync(
      encryptedJson,
      process.env.PRIVATE_KEY_PASSWORD
    );

project dependencies

{
  "dependencies": {
    "dotenv": "^16.0.3",
    "ethers": "^6.3.0",
    "fs-extra": "^11.1.1",
    "solc": "^0.8.7-fixed"
  },
  "scripts": {
    "compile": "yarn solcjs --bin --abi --include-path node_modules/ --base-path . -o . SimpleStorage.sol"
  }
}
gracecampo commented 1 year ago

Hope you can help me take a look, thank you very much

gracecampo commented 1 year ago

Hey, I found the problem, my PRIVATE KEY The PASSOWRD obtained is empty, which is strange. I clearly saved it

summer739 commented 1 year ago

just remove "new" let wallet = ethers.Wallet.fromEncryptedJsonSync( encryptedJson, process.env.PRIVATE_KEY_PASSWORD );