Solidity 如何在使用web3进行测试时将参数传递给构造函数
我需要使用Solidity 如何在使用web3进行测试时将参数传递给构造函数,solidity,smartcontracts,web3,Solidity,Smartcontracts,Web3,我需要使用web3和ganache cli测试我的合同。在合同中,我必须向构造函数函数发送参数。如何在使用web3部署时执行此操作 factory = await web3.eth.Contract(JSON.parse(compiledFactory.interface)) .deploy({ data: compiledFactory.byteCode, }) .send({ from: accounts[0], gas: "100
web3
和ganache cli
测试我的合同。在合同中,我必须向构造函数
函数发送参数
。如何在使用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;
}
}
我在堆栈交换中遇到过这个问题,但我无法解决它。您可以通过向
.deploy()
函数的参数属性提供数据来解决
contractInstance = await new web3.eth.Contract(interface).deploy({
data: bytecode,
arguments: [INITIAL_minimum]
}).send({
from: accounts[0],
gas: 1000000
});