如何在使用 web3 进行测试时将我的参数传递给构造函数

how to pass my arguments to constructor function while testing using web3

我需要使用 web3ganache-cli 测试我的合约。在我的合同中,我必须将 argument 发送到 constructor 函数。如何在使用 web3 部署时执行此操作。

factory = await web3.eth.Contract(JSON.parse(compiledFactory.interface))
    .deploy({
      data: compiledFactory.byteCode,
    })
    .send({
      from: accounts[0],
      gas: "1000000",
    });

我的合同是,

contract Factory{
    CrowdFunding[] public deployedContractAddresses;

    constructor(uint minimum) public {
        CrowdFunding newContract = new CrowdFunding(minimum, msg.sender);
        deployedContractAddresses.push(newContract);
    }

    function getDeployedContractAddresses() public view returns(CrowdFunding[] memory) {
        return deployedContractAddresses;
    }
}

我已经在堆栈交换中经历了这个link,但我无法解决它。

您可以通过向 .deploy() 函数的 arguments 属性 提供数据来实现。

    contractInstance = await new web3.eth.Contract(interface).deploy({
        data: bytecode,
        arguments: [INITIAL_minimum]
    }).send({
        from: accounts[0],
        gas: 1000000
    });