noteNote that the gas price can fluctuate rapidly, so it is always best to check the gas price before deploying your contract. You can do this using a gas price estimator such as EthGasStation or Etherscan.
const MyContract = await ethers.getContractFactory('MyContract', signer);
const mycontract = await MyContract.deploy({
gasPrice: 1000000000000000000, // 100 Gwei
gasLimit: 6660666,
});
const MyContract = await ethers.getContractFactory('MyContract', signer); const mycontract = await MyContract.deploy({ gasPrice: 1000000000000000000, // 100 Gwei gasLimit: 6660666, }); TheThe feeData object that you mentioned in your question is a new feature that was introduced in EIP-1559. It provides a more flexible way to specify the gas fees for a transaction.
const feeData = await provider.getFeeData();
const feeData = await provider.getFeeData();
const MyContract = await ethers.getContractFactory('MyContract', signer);
const mycontract = await MyContract.deploy(feeData);
const MyContract = await ethers.getContractFactory('MyContract', signer); const mycontract = await MyContract.deploy(feeData); TheThe provider.getFeeData() method returns a FeeData object that contains the following information:
maxFeePerGas: The maximum fee per gas that the user is willing to pay. maxPriorityFeePerGas: The maximum priority fee per gas that the user is willing to pay.
maxFeePerGas: The maximum fee per gas that the user is willing to pay. maxPriorityFeePerGas: The maximum priority fee per gas that the user is willing to pay. gasPricegasPrice: The base fee per gas that will be paid to the miner. The maxFeePerGas and maxPriorityFeePerGas values are specified in Gwei. The gasPrice value is specified in Wei.
If you are using Hardhat, you can use the getFeeData() methoduse the getFeeData() method from the ethers package. For example:
const { getFeeData } = require('ethers');
const { getFeeData } = require('ethers');
const feeData = await getFeeData();
const feeData = await getFeeData(); OnceOnce you have the feeData object, you can pass it to the deploy() method when deploying your contract.
Here is a summary of the two methods:
Method 1: Using the feeData objectUsing the feeData object
// Get the fee data from the provider. const feeData = await provider.getFeeData();
// Get the fee data from the provider.
const feeData = await provider.getFeeData();
// Deploy the contract using the fee data.
const MyContract = await ethers.getContractFactory('MyContract', signer);
const mycontract = await MyContract.deploy(feeData);
// Deploy the contract using the fee data. const MyContract = await ethers.getContractFactory('MyContract', signer); const mycontract = await MyContract.deploy(feeData); Method Method 2: Using the gasPrice and gasLimit options
// Specify the gas price and gas limit. const gasPrice = 1000000000000000000; // 100 Gwei const gasLimit = 6660666;Using the gasPrice and gasLimit options
// Deploy the contract using the gas price and gas limit options. const MyContract = await ethers.getContractFactory('MyContract', signer); const mycontract = await MyContract.deploy({ gasPrice, gasLimit, });
// Specify the gas price and gas limit.
const gasPrice = 1000000000000000000; // 100 Gwei
const gasLimit = 6660666;
// Deploy the contract using the gas price and gas limit options.
const MyContract = await ethers.getContractFactory('MyContract', signer);
const mycontract = await MyContract.deploy({
gasPrice,
gasLimit,
});