is gasLimit param should be defined or not.....? #4136
-
Hi, I have a script that sends different TXs in different chains and.... it seems like some TXs are stuck or just take too much time to be sent.... So I'm trying to get what happens if I don't specify the gasLimit and should I really do it at all? the behavior seems to be random and I cannot get any logical answer from it.... I would really appreciate someone explain it to me,.. do I have to define it, or not, and which is better. Does it behave the same for legact TXs and EIP 1559 ones.. Btw are there only two type of TXs right now? legacy and EIP 1559? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
The gasLimit has never changed in meaning. In the gas analogy, it is simply how big a gas tank to give your transaction. You pay upfront to fill it up (based on the transaction fee data, which has changed over time from gasPrice in legacy and type 1 transactions to maxFeePerGas and maxPriorityFeePerGas in type 2 (EIP-1559) transactions) and are refunded for any unused gas at the end of the transaction. The gasLimit though should have no bearing on whether a tx gets included, since if the gas tank is too small it will just run out early, but the miner will have received payment for it despite your tx failing (running out of gas). In ethers, leaving the gasLimit unspecified will result in ethers using estimateGas to try guessing for you. This is usually fine, and unless you know a better value to use (for example, Vyper can actually compute this for you and include it in the ABI at compile time and is likely a much better solution, but at the cost of some flexibility). On Ethereum there is actually only EIP-1559 transactions currently. If you use either legacy or type 1 transactions, they are converted to type 2 transactions with gasPrice used as both maxFeePerGas and maxPriorityFeePerGas; this will result in a very overpriced transaction, so it highly discouraged. Using correct EIP-1559 fee data is best for everyone. :) If your txs are getting stuck, it is likely you are using either too low of a maxFeePerGas (should be 2x the most recent block’s baseFee), maxPriorityFeePerGas (1 gwei should be fine though) or the network is under severe congestion. Does that all make sense? |
Beta Was this translation helpful? Give feedback.
The gasLimit has never changed in meaning. In the gas analogy, it is simply how big a gas tank to give your transaction. You pay upfront to fill it up (based on the transaction fee data, which has changed over time from gasPrice in legacy and type 1 transactions to maxFeePerGas and maxPriorityFeePerGas in type 2 (EIP-1559) transactions) and are refunded for any unused gas at the end of the transaction.
The gasLimit though should have no bearing on whether a tx gets included, since if the gas tank is too small it will just run out early, but the miner will have received payment for it despite your tx failing (running out of gas).
In ethers, leaving the gasLimit unspecified will result in e…