部署 Solidity 合约时出错:预期有 0 个构造函数参数,但得到了 6 个

问题描述 投票:0回答:1

我正在尝试使用 Hardhat 中的部署脚本来部署 Solidity 合约。但是,我在部署过程中遇到了错误。我使用Hardhat作为我的开发环境,并且我已经成功编译了合约。但是,部署期间提供的字节码或数据似乎存在问题。我收到的错误消息如下:

Error: expected 0 constructor arguments, got 6

部署脚本

const { network, ethers } = require("hardhat");
const {
  developmentChains,
  networkConfig,
  VERIFICATION_BLOCK_CONFIRMATIONS
} = require("../helper-hardhat-config.js");
const { verify } = require("../utils/verify");

console.log("I've reached here");

const VRF_SUB_FUND_AMOUNT = ethers.utils.parseEther("1");

module.exports = async ({ getNamedAccounts, deployments }) => {
  const { deploy, log } = deployments;
  const { deployer } = await getNamedAccounts();
  let chainId = network.config.chainId;
  let vrfCoordinatorV2Address, subscriptionId, vrfCoordinatorV2Mock;

console.log("i've reached here")

  console.log(`chainId 01 : ${chainId}`)
  console.log("inside the 01-deploy-raffle.js");
  if (developmentChains.includes(network.name)) {
    vrfCoordinatorV2Mock = await ethers.getContract(
      "VRFCoordinatorV2Mock"
    );
    console.log("after mock");

    vrfCoordinatorV2Address = await vrfCoordinatorV2Mock.address;

    console.log(`Address ${vrfCoordinatorV2Address}`)
    const txResponse = await vrfCoordinatorV2Mock.createSubscription();
    const txReceipt = await txResponse.wait(1);
    subscriptionId = txReceipt.events[0].args.subId;
    // usually you will need Link token to fund the sub on a real network
    await vrfCoordinatorV2Mock.fundSubscription(
      subscriptionId,
      VRF_SUB_FUND_AMOUNT
    );
  } else {
    vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorV2"];
    subscriptionId = networkConfig[chainId]["subscriptionId"];
  }
  const waitBlockConfirmations = developmentChains.includes(network.name)
  ? 1
  : VERIFICATION_BLOCK_CONFIRMATIONS

log("----------------------------------------------------")

const entranceFee = networkConfig[chainId]["entranceFee"];
const gasLane = networkConfig[chainId]["gasLane"];
const callBackGasLimit = networkConfig[chainId]["callBackGasLimit"];
const interval = networkConfig[chainId]["interval"];

const args = [entranceFee, vrfCoordinatorV2Address, gasLane, subscriptionId, callBackGasLimit, interval];

//Error starts here!!

const lottery = await deploy("Lottery", {
  from: deployer,
  args: args,
  log: true,
  waitConfirmations: network.config.blockConfirmations || 1,
});

// Rest of the script...

可靠性代码

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";
import "@chainlink/contracts/src/v0.8/interfaces/AutomationCompatibleInterface.sol";

      abstract contract Lottery is VRFConsumerBaseV2, AutomationCompatibleInterface {
    // types/ enums
    enum LotteryState {
        open,
        calculating
    }

    // state variables
    uint256 private immutable i_entranceFee;
    address payable[] private s_players;
    VRFCoordinatorV2Interface private immutable i_vrfCoordinator;
    bytes32 private immutable i_gasLane;
    uint64 private immutable i_subscriptionId;
    uint16 private constant REQUEST_CONFIRMATIONS = 3;
    uint32 private immutable i_callBackGasLimit;
    uint32 private constant NUM_WORDS = 1;

    // lottery variables
    address private s_recentWinnerAddress;
    LotteryState private s_LotteryState;
    uint256 private s_LastTimeStamp;
    uint256 private immutable i_Interval;

    // events
    event LotteryEnter(address indexed player);
    event RequestedLotteryWinner(uint256 indexed requestId);
    event WinnerPicked(address indexed winner);

constructor(
    uint256 entranceFee,
    address vrfCoordinatorV2,
    bytes32 gasLane,
    uint64 subscriptionId,
    uint32 callBackGasLimit,
    uint256 interval
)
    VRFConsumerBaseV2(vrfCoordinatorV2)
{
            i_entranceFee = entranceFee;
        i_vrfCoordinator = VRFCoordinatorV2Interface(vrfCoordinatorV2);
        i_gasLane = gasLane;
        i_subscriptionId = subscriptionId;
        i_callBackGasLimit = callBackGasLimit;
        s_LotteryState = LotteryState.open;
        s_LastTimeStamp = block.timestamp;
        i_Interval = interval;
}
//Rest of the code

我怀疑该问题可能与部署期间未正确提供字节码有关。我已经验证合约已成功编译并且字节码在artifacts/目录中可用。

有人可以帮我解决这个错误吗?部署过程中出现错误可能是什么原因导致的?

constructor solidity smartcontracts hardhat constructorargument
1个回答
0
投票

检查您的工件,您会发现没有生成任何字节码,要修复此错误,请确保您的合约不是抽象合约。

"bytecode": "0x",
  "deployedBytecode": "0x",
  "linkReferences": {},
  "deployedLinkReferences": {}

这可能是您会在工件中找到的内容,

"bytecode": "0x"
意味着没有为您的合约生成任何字节码!

© www.soinside.com 2019 - 2024. All rights reserved.