I have an interesting phenomena EDIT: on the Fantom network, sorry if this is the wrong place to ask which I do not understand, so maybe someone is able to explain this:

When I send a transaction with e.g. 400000 gas limit to execute my contract method, X amount of gas is used. When I send the exact same transaction with only 250000 limit, a much lower amount of gas is used.

Example 1:

Gas Limit: 400,000

Gas Used by Transaction: 80,726 (20.18%)

Gas Price: 0.0000002455336 FTM (245.5336 Gwei)


Gas Limit: 250,000

Gas Used by Transaction: 65,726 (26.29%)

Gas Price: 0.0000002310364 FTM (231.0364 Gwei)

Note: The method executes exactly the same code in both transactions, so there is no condition different or so.

Why is that so?


I just tried another sequence, first with lower gas, then with higher gas limit:

Example 3:

Gas Limit: 350,000

Gas Used by Transaction:72,650 (20.76%)

Example 4:

Gas Limit: 450,000

Gas Used by Transaction: 82,650 (18.37%)

1 Answer 1


Are you resetting the blockchain state after each transaction, or do you execute example 2 after example 1?

If the latter, that might be the reason for the lesser gas amount. For example, in a general ERC721 implementation, the mint function spends less gas the second time you call it.

  • Yes, 2 was executed after 1. Will try again. Not sure what you mean with resetting the blockchain state. These are transactions on the mainnet. Or do you mean if I changed the my contract storage variables? Also no. I just hand over the same input to the method. The method itself does not change the storage, does only internal caluclations, apart from one external call to getReserves() on an Uniswap pair. EDIT: Please check edit in OP
    – flo
    Jan 2, 2022 at 14:06
  • Since the blockchain state is different after every transaction, and more so if it's mainnet (which can even change outside of your transactions), you can't really compare transactions like that. You need to make sure the state is the same when comparing, otherwise you might get different result. If you're running on mainnet, one way to do it would be using hardhat to do mainnet forking - meaning, simulating the mainnet locally on your pc - you tell it to simulate the blockchain at a certain block, then run tx 1, then again simulate from the same block before you ran your tx, then run..... Jan 2, 2022 at 15:00
  • ....tx 2. This way you'll run both of them on the same state and then the comparison will be more accurate. By the way, it's a little strange that you say they don't update storage variables. If they didn't update any contract's state, you wouldn't even need to spend gas to execute them. Jan 2, 2022 at 15:02
  • 1
    Thanks Kenzo for your feedback. I will check and come back :)
    – flo
    Jan 3, 2022 at 11:14
  • 1
    Cheers mate :) I realized there's another thing you can check - examples 1 and 2 are the exact same tx, only different gas limit right? So you can try executing the same tx twice in a row with same gas limit, and see if the gas consumption will change or not. Jan 3, 2022 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.