I am using ethers as part of hardhat and I'm preparing to deploy to mainnet. I am using the gas-estimator plugin, and I see how much gas is used during each test/testnet deployment. However, so far, I haven't once had to specify gas for a transaction or deployment.
This is scary, as I know from the past deploying to mainnet is a bit different.
In the past I kinda just put in an arbitrarily high gasLimit, which seems wrong, like this:
const token = await ethers.getContractFactory("CreepKidsNFT");
const contract = await token.deploy({
gasLimit:6660666
});
I haven't been able to find any clear answer or documentation on what exactly is going on under the hood. It seems like this would be something there is clear documentation/sample code somewhere... Maybe this can be that place?
If I run this code, will ethers handle getting the gas price and submitting a "market rate" amount of gas?
const MyContract = await ethers.getContractFactory("MyContract");
const myContract = await MyContract.deploy();
Or do I need to do something like, run tests, get gas used from gas-estimator, figure out that amount in wei, and supply gasPrice, maxFeePerGas, maxPriorityFeePerGas as options?
I see what looks like a single call way of handling a similar process done on the answer provided by Diego Ferri here in which he makes a "feeData" provider call
// The gas price (in wei)...
const feeData = await provider.getFeeData();
And then he just passes that in as the contract options
const MyContract = await ethers.getContractFactory('MyContract', signer);
const mycontract = await MyContract.deploy(feeData);
Is this the way?
And if it is the way how do we do this in hardhat, specifically the provider.getFeeData() part?
It's my understanding that ethers is the provider for hardhat, but I don't see any function call like getFeeData in the helpers api