# Why the transaction fee in blockchains change?

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?

## 1 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

Depends on how the network is at that moment?

exactly, here you can read more about how the gas price can change

If the last block was exactly 50% full, the Base Fee will remain unchanged. If the last block was 100% full, the Base Fee will increase by the maximum 12.5% for the next block.

If the last block was more than 50% full but less than 100% full, the Base Fee will increase by less than 12.5%.

If the last block was 0% full – that is, empty – the Base fee will decrease the maximum 12.5% for the next block.

If the last block was more than 0% full but less than 50% full, the Base Fee will decrease by less than 12.5%

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