trying to calculate how much a contract would cost if it were deployed to mainnet. The code i have only get the gas for the constructor arguments and not the whole contract. I have searched online but i haven't found anything that actually gets the whole contract bytecode gas cost. What am i missing here? I am using ethers and hardhat btw
const [owner] = await ethers.getSigners();
const provider = new ethers.providers.JsonRpcProvider(
https://mainnet.infura.io/v3/${process.env.INFURA_KEY}
);
const feeData = await provider.getFeeData();
const gasPrice = feeData.gasPrice!;
console.log(
"Max Fee Per Gas: ",
utils.formatUnits(feeData.maxFeePerGas!, "gwei")
);
console.log("Gas Price: ", utils.formatUnits(feeData.gasPrice!, "gwei"));
console.log(
"Max Priority Fee Per Gas: ",
utils.formatUnits(feeData.maxPriorityFeePerGas!, "gwei")
);
const Contract_Name = await ethers.getContractFactory(
"Contract_Name",
owner
);
const bytecode = Contract_Name.interface.encodeDeploy([
"a",
"b",
]);
const gasPriceContract = await provider.estimateGas({ data: bytecode });
console.log(
"Gas Price Contract: ",
formatEther(gasPrice.mul(gasPriceContract))
);
Testnet will give you value
Обсуждают сегодня