小编Vit*_*nna的帖子

类型错误:ethers.Wallet.fromEncryptedJsonSync 不是构造函数

我正在尝试运行这段代码,以使用 ethers.js 库在 JS 中部署智能合约:

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

async function main() {
  const provider = new ethers.ethers.JsonRpcProvider(process.env.RPC_URL);
  // reads the json private key from file
  const encryptedJson = fs.readFileSync("./.encryptedKey.json", "utf-8");
  
// ========= START FAILING PART ============
  let wallet = new ethers.Wallet.fromEncryptedJsonSync(
    encryptedJson,
    process.env.PRIVATE_KEY_PASSWORD
  );
// ========= END FAILING PART ============
  
  wallet = await wallet.connect(provider);
  const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf-8");
  const binary = fs.readFileSync(
    "./SimpleStorage_sol_SimpleStorage.bin",
    "utf-8"
  );
  
  const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
  console.log("Deploying, …
Run Code Online (Sandbox Code Playgroud)

javascript node.js blockchain smartcontracts ethers.js

-3
推荐指数
1
解决办法
652
查看次数