I would like to understand why when making a transaction in the blockchain, the fees change.
Being in the polygon network, I execute the same contract 10 times and the transaction price is always different.
For example, I deploy contract A.
The first deploy costs me 0.1945 ETH.
The second deploy costs me 0.2042 ETH.
The third deploy costs me 0.1994 ETH
The contract is the same, nothing changes, what I don't understand is why sometimes it is more expensive to execute it and sometimes cheaper.
Depends on how the network is at that moment?
Best Answer
the reason is the gas price it can change from block to block. If you are deploying the same smart contract multiple times, the gas used will be the same but the gas price could be different depending on the network
exactly, here you can read more about how the gas price can change
take a look at the following transactions and how the transaction fee is calculated:
here you have a legacy transaction (Txn type 0) and as you can see the gas used was 21000 units.
The gas price at that moment was 0.000000008 Ether so
0.000000008 * 21000 = 0.000168 Ether
here you have another transaction in this case a Txn type 2
as you can see the base fee = 0,000000007 and the max priority fee = 2.5 so the gas price = 0,000000007 + 2.5 = 2,500000007 Gwei = 0,0000000025000000007 Ether
the gas used is 102411 then the transaction fee was = 0,0000000025000000007 * 102411 = 0,0002560275000716877 Ether