【问题标题】:NomicLabsHardhatPluginError: The constructor for contracts/FundMe.sol:FundMe has 1 parameters but 0 arguments were provided instead at encodeArgumentNomicLabsHardhatPluginError: Contracts/FundMe.sol:FundMe 的构造函数有 1 个参数,但在 encodeArgument 处提供了 0 个参数
【发布时间】:2022-09-24 13:51:57
【问题描述】:

这是我得到的错误。

我在没有验证 etherscan 的情况下尝试了它,它仍然给出了同样的错误我在 goerli 网络上部署它 请看看那个请

yarn run v1.22.15
warning ..\\package.json: No license field
$ \"E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\.bin\\hardhat\" deploy --tags all --network goerli
Nothing to compile
5
ethUsdPriceFeedAddress 0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e
reusing \"FundMe\" at 0x6DD6B9f3bD775549Ef0e6423C49c9d03AC6bb778
Verifying Contracts.........
Nothing to compile
NomicLabsHardhatPluginError: The constructor for contracts/FundMe.sol:FundMe has 1 parameters
but 0 arguments were provided instead.
    at encodeArguments (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\@nomiclabs\\hardhat-etherscan\\src\\ABIEncoder.ts:29:13)
    at SimpleTaskDefinition.verifySubtask [as action] (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\@nomiclabs\\hardhat-etherscan\\src\\index.ts:283:34)
    at Environment._runTaskDefinition (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\hardhat\\src\\internal\\core\\runtime-environment.ts:219:14)
    at Environment.run (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\hardhat\\src\\internal\\core\\runtime-environment.ts:131:14)
    at verify (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\utils\\verify.js:6:9)
    at Object.module.exports [as func] (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\deploy\\01_fudme_deploy.js:31:9)
    at DeploymentsManager.executeDeployScripts (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\hardhat-deploy\\src\\DeploymentsManager.ts:1219:22)
    at DeploymentsManager.runDeploy (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\hardhat-deploy\\src\\DeploymentsManager.ts:1052:5)
    at SimpleTaskDefinition.action (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\hardhat-deploy\\src\\index.ts:438:5)
    at Environment._runTaskDefinition (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\hardhat\\src\\internal\\core\\runtime-environment.ts:219:14)

    Caused by: Error: types/values length mismatch (count={\"types\":1,\"values\":0}, value={\"types\":[{\"name\":\"priceFeed\",\"type\":\"address\",\"indexed\":null,\"components\":null,\"arrayLength\":null,\"arrayChildren\":null,\"baseType\":\"address\",\"_isParamType\":true}],\"values\":[]}, code=INVALID_ARGUMENT, version=abi/5.7.0)        at Logger.makeError (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\@ethersproject\\logger\\src.ts\\index.ts:269:28)
        at Logger.throwError (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\@ethersproject\\logger\\src.ts\\index.ts:281:20)
        at AbiCoder.encode (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\@ethersproject\\abi\\src.ts\\abi-coder.ts:101:20)
        at Interface._encodeParams (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\@ethersproject\\abi\\src.ts\\interface.ts:323:31)
        at Interface.encodeDeploy (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\@ethersproject\\abi\\src.ts\\interface.ts:327:21)
        at encodeArguments (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\@nomiclabs\\hardhat-etherscan\\src\\ABIEncoder.ts:22:8)
        at SimpleTaskDefinition.verifySubtask [as action] (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\@nomiclabs\\hardhat-etherscan\\src\\index.ts:283:34)
        at Environment._runTaskDefinition (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\hardhat\\src\\internal\\core\\runtime-environment.ts:219:14)
        at Environment.run (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\node_modules\\hardhat\\src\\internal\\core\\runtime-environment.ts:131:14)
        at verify (E:\\Block Chain Projects\\FUND_ME_FULLSTACK\\utils\\verify.js:6:9)

我的 00_fundme_deploy.js我正在尝试部署一个众筹项目它已正确部署在安全帽 localhost 网络上,但它在 goerli 网络上引发错误

const {networkconfig,developmentChains} = require(\"../helper-hardhat-config\")
const {getNamedAccounts,deployments,network} = require(\"hardhat\");
const {verify} = require(\"../utils/verify.js\");
require(\"dotenv\").config();
    module.exports = async ({getNamedAccounts,deployments}) =>{
    const {deploy,log} = deployments;
    const {deployer}= await  getNamedAccounts();
    const chainID = network.config.chainId;
    console.log(chainID)

    //IF chain ID is A then use address B
    // IF CHAINID IS Z THEN USE C
    let ethUsdPriceFeedAddress
    if (chainID == 31337) {
        const ethUsdAggregator = await deployments.get(\"MockV3Aggregator\")
        ethUsdPriceFeedAddress = ethUsdAggregator.address
    } else {
        ethUsdPriceFeedAddress = networkconfig[chainID][\"ethUsdPriceFeed\"]
    }
    // if the Price feed contract doesnt\'t exists then we deploy a 
    //minimal version of our testing
    console.log(\"ethUsdPriceFeedAddress\",ethUsdPriceFeedAddress)
    // deploy on the another network 
    const fundme = await deploy(\"FundMe\",{
        from:deployer,
        args: [ethUsdPriceFeedAddress],
        log:true,
        waitconfirmations:network.config.blockConfirmations  || 1,
    })
    if(!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY){
        await verify(fundme.address, [ethUsdPriceFeedAddress])
    }
    log(\"------------------------------------------\");
}
module.exports.tags = [\"fund\",\"all\"];

FundMe.sol 的构造函数

constructor(address priceFeed) {
        s_priceFeed = AggregatorV3Interface(priceFeed);
        i_owner = msg.sender;
    }

它需要一个参数(Pricefeed)

  • 由于某种原因 args: [ethUsdPriceFeedAddress]ethUsdPriceFeedAddress 未定义在哪里。做了这个日志console.log(\"ethUsdPriceFeedAddress\",ethUsdPriceFeedAddress)
  • 我推测当它是非本地安全帽环境时,例如chainId !== 31337 它在 else 中赋值,networkconfig 拼写错误应该是 networkConfig。或 network.config.chainId 返回的链 ID 是字符串,在您的配置中它的类型为 number,反之亦然。

标签: node.js solidity yarnpkg hardhat


【解决方案1】:

您的问题不在于部署,而在于验证,对吗?如果是这样,我认为这可能会有所帮助,因为我刚刚遇到了同样的错误......

检查您的 verify.js 脚本。这是我遇到错误时的样子(verify.ts):

import { run } from "hardhat"

async function verify(address: string, args: any) {
  console.log("Verifying contract...")
  try {
    await run("verify:verify", {
      address: address,
      constructorArgs: args <-- THIS WAS THE ISSUE -->
    })
  } catch (error: any) {
    if (error.message.toLowerCase().includes("already verified")) {
      console.log("Already verified")
    } else {
      console.error(error)
    }
  }
}

export default verify

我把它改成这样:

import { run } from "hardhat"

async function verify(address: string, args: any) {
  console.log("Verifying contract...")
  try {
    await run("verify:verify", {
      address: address,
      constructorArguments: args <-- THIS WAS THE ISSUE -->
    })
  } catch (error: any) {
    if (error.message.toLowerCase().includes("already verified")) {
      console.log("Already verified")
    } else {
      console.error(error)
    }
  }
}

export default verify

我相信这是一个自动完成错误!

【讨论】:

    【解决方案2】:

    如果您可以转换为打字稿,则将其用于 javascript 用户

    const { run } = require("hardhat")
    
    const verify = async function verify(contractAdress, args) {
        console.log("verifying contract !!!!!!!")
    
        try {
            await run("verify:verify", {
                address: contractAdress,
                constructorArguments: args,
            })
        } catch (e) {
            if (e.message.toLowerCase().includes("already verified")) {
                console.log("already verified")
            } else {
                console.log(e)
            }
        }
    }
    
    module.exports = {
        verify,
    } 
    

    我现在遇到了同样的问题,我必须将函数等同于变量 verify,然后从 module.exports 导出它

    【讨论】:

      猜你喜欢
      • 2018-03-23
      • 2018-05-13
      • 2012-02-11
      • 2017-09-15
      • 1970-01-01
      • 2014-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多