NodeJS 在测试中使用ethers.utils.parseEther(“1”)时遇到未定义的错误

eeq64g8w  于 2022-12-18  发布在  Node.js
关注(0)|答案(1)|浏览(235)
let fundMe
   let mockV3Aggregator
   let deployer
   const sendValue = ethers.utils.parseEther("1")
beforeEach(async () => {
       // const accounts = await ethers.getSigners()
       // deployer = accounts[0]
       deployer = (await getNamedAccounts()).deployer
       await deployments.fixture(["all"])
       fundMe = await ethers.getContractAt("FundMe", deployer)
       mockV3Aggregator = await ethers.getContractAt(
           "MockV3Aggregator",
           deployer
       )
   }

错误消息:TypeError:无法读取未定义的属性(阅读“utils”)
另外,我尝试将值直接输入到sendValue变量,然后弹出以下错误:类型错误:无法读取未定义的属性(阅读“getContract”)
PS:我的utils文件夹中填充了以下代码

const { run } = require("hardhat")
async function verify(contractAddress, args) {
    console.log("Verifying contract..")
    try {
        await run("verify:verify", {
            // verify:verify the second verify is the subtask of thje actual verify task and {} is the object containing the actual parameters
            address: contractAddress,
            ConstructorArguments: args,
        })
    } catch (e) {} // to catch any errors
    if (e.message.toLowerCase().includes("already verified")) {
        console.log("Already Verified")
    } else {
        console.log(e)
    }
}
module.exports = { verify }
gfttwv5a

gfttwv5a1#

ethers未定义,您可能没有导入它

const {ethers } = require("hardhat")

相关问题