简体   繁体   English

hardhat 部署方法不再与基金一起工作如何为合同提供资金?

[英]hardhat deploy method not working anymore with fund how to fund the contract?

So I have written the same code as the hardhat documentation suggest here for deploying with funding maybe.因此,我编写了与此处建议的 hardhat 文档相同的代码,用于可能需要资金进行部署。

import hre from "hardhat";

const main = async () => {
  const currentTimestampInSeconds = Math.round(Date.now() / 1000);
  const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
  const unlockTime = currentTimestampInSeconds + ONE_YEAR_IN_SECS;
  const lockedAmount = hre.ethers.utils.parseEther("1");

  const waveContractFactory = await hre.ethers.getContractFactory("WavePortal");
  const waveContract = await waveContractFactory.deploy(unlockTime,
    { value: lockedAmount }
  );
  await waveContract.deployed();
  console.log("Contract deployed to:", waveContract.address);
}

but the problem is it will give me an error about the argument.但问题是它会给我一个关于论点的错误。 在此处输入图像描述

even if it's the same code that the documentation suggest here: https://hardhat.org/hardhat-runner/docs/guides/deploying .即使它与此处文档建议的代码相同: https://hardhat.org/hardhat-runner/docs/guides/deploying

First I have written code in a different manner from buildspace website as a part of learning about web3.首先,作为学习 web3 的一部分,我以不同于buildspace网站的方式编写代码。

// from buildspace website
const main = async () => {
  const waveContractFactory = await hre.ethers.getContractFactory("WavePortal");
  const waveContract = await waveContractFactory.deploy({
    value: hre.ethers.utils.parseEther("0.001"),
  });

  await waveContract.deployed();

  console.log("WavePortal address: ", waveContract.address);
};

This above code from buildspace but the problem is it will also give the error and I thought it could be the old deprecated code so I look into docs.上面的代码来自buildspace ,但问题是它也会给出错误,我认为它可能是旧的已弃用代码,所以我查看了文档。

The JS deploy() function accepts N required params, followed by 1 optional: JS deploy() function 接受 N 个必需参数,后跟 1 个可选参数:

  • N arguments of the Solidity constructor Solidity构造函数的N arguments
  • 1 optional object that overrides default params of the deploying transaction (in your case the value ) 1 个可选的 object覆盖部署交易的默认参数(在您的情况下为value

Based on the error message "Expected 0-1 arguments", the WavePortal constructor expects 0 params.根据错误消息“Expected 0-1 arguments”, WavePortal构造函数需要 0 个参数。 Which makes the deploy() function to expect 0 constructor params, plus the 1 optional overriding object.这使得deploy() function 期望 0 个构造函数参数,加上 1 个可选的覆盖 object。

However your code is trying to pass unlockTime as the constructor param.但是,您的代码试图将unlockTime作为构造函数参数传递。

Solution: Remove the unlockTime from the JS code - or accept it in the Solidity code.解决方案:从 JS 代码中删除unlockTime - 或者在 Solidity 代码中接受它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM