我试图在ethers.js上制作一个ethers.js,并通过炼金术在波利贡的测试网孟买部署智能合同。
我对deploy函数有一个问题,就像在文档中一样,不清楚如何格式化参数。
作为炼金术文档,我必须指定gasLimit和gasPrice,但我也希望为契约的构造函数指定自定义参数。
我所犯的错误:
gasLimit和gasPrice参数gasLimit和gasPrice的参数,那么由于参数的顺序,智能契约的构造函数会出现问题。gasLimit和gasPrice,它将正确部署,但我没有我想要的自定义智能契约,因为构造函数的参数丢失了;这是部署智能契约的代码段:
const price_unit = "gwei";
const contractFile = await fs.readFileSync('artifacts/contracts/Midly.sol/NFTCollectible.json');
const contract = JSON.parse(contractFile.toString());
const provider = new ethers.providers.AlchemyProvider("maticmum", process.env.ALCHEMY_API_KEY);
const wallet = new ethers.Wallet(process.env.WALLET_PRIVATE_KEY, provider);
const price = ethers.utils.formatUnits(await provider.getGasPrice(), price_unit);
const factory = new ethers.ContractFactory(contract.abi, contract.bytecode, wallet);
const deployedContract = await factory.deploy({
gasLimit: 2,
gasPrice: ethers.utils.parseUnits(price, price_unit),
}, tokenURI, maxQuantity, cost)
.then(data => console.log(data))
.catch(error => console.log(error));谢谢你抽出时间:)
发布于 2022-03-12 16:08:24
您需要首先传递构造函数参数,最后传递overrides对象。
const deployedContract = await factory.deploy(tokenURI, maxQuantity, cost, {
gasLimit: 2,
gasPrice: ethers.utils.parseUnits(price, price_unit),
})博士:https://docs.ethers.io/v5/api/contract/contract-factory/#ContractFactory-deploy
https://stackoverflow.com/questions/71450647
复制相似问题