[英]Ethers.js Contract Factories
我正在嘗試在 ethers.js 上創建一個 ContractFactory,並通過 Alchemy 在 Polygon 的 tes.net Mumbai 上部署智能合約。
我在部署 function 時遇到問題,因為在文檔中不清楚如何格式化 arguments。
作為 Alchemy 文檔,我必須指定gasLimit
和gasPrice
,但我還想為我的合約構造函數指定自定義 arguments 。
我得到的錯誤:
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));
謝謝你的時間:)
您需要首先傳遞構造函數 arguments,最后傳遞overrides
object。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.