How to control my gas price during the transaction process?

How can I control my gas price during the transaction process? I've found that i should set the gasPrice in hardhat.config.js. I've also seen people saying about setting maxPriorityFeePerGas and maxFeePerGas. However, these options are not appearing in the Hardhat documentation. So, what are the differences between them, and how should I set them effectively?

The previous London upgrade introduced the EIP-1559 , which changed the gas fee structure. Gas fees are now divided into the priority fee and the basic fee. The basic fee is dynamically adjusted based on the state of the blockchain, and this fee will be burned. The priority fee serves as a tip for miners, setting a higher priority fee can have higher chance for quicker execution by miners. The maxPriorityFeePerGas is the maximum tip per unit of gas paid to miners, while maxFeePerGas is the sum of maxPriorityFeePerGas and basicFeePerGas.

2 Likes

how to set these two?

example:

const txn= await contract.yourFunction({
      maxFeePerGas : 50000000000, // 50 gwei
      maxPriorityFeePerGas : 50000000000 //50 gwei
    });

You can adjust the gas fee settings yourself.

1 Like

Something is not made entirely clear here.

Previously, there used to be a single parameter which controlled the gas price (named gasPrice), allowing you to increase the chance for quicker execution in a straightforward manner, by increasing the value of that one parameter.

Now there are two parameters, which means that increasing the chance for quicker execution becomes a two-dimensional optimization problem.

According to the first part in your answer, the basic fee is dynamically adjusted based on the state of the blockchain, which implies that the user doesn't need to worry about it, and can still increase the chance for quicker execution in a straightforward manner, by increasing the value of the other parameter.

However, according to the second part in your answer, that basic fee IS in fact controlled by the user, as it is implicitly set to be the difference between the two parameters provided by the user, which "once again" turns it into a two-dimensional optimization problem.

Anyway, the part which I find to be not entirely clear is - how should one go about setting these two parameters based on how fast they want their transaction executed?

Thanks

1 Like

Yes.
the actual determinant of whether it can be executed quickly depends on maxPriorityFeePerGas, as a higher maxPriorityFeePerGas signifies greater earnings for miners.
Setting maxFeePerGas is just to ensure that the basic fee doesn't suddenly spike, causing the total fee to exceed expectations.

1 Like

So in short:

  • maxPriorityFeePerGas controls how fast the transaction is likely to be executed
  • maxFeePerGas protects the caller from paying more gas than the maximum desired

Is this description accurate?

2 Likes

Yes, it's correct. :grinning:

1 Like

I have follow question, so in terms if want to rush my transaction and increase by 10 gwei the fee. So I need to incrase by 10 gwei both parameters correct ?
maxFeeperGas+= 10 gwei
maxPriorityFeePerGas+= 10 gwei