How to Calculate Tezos Fees

I am programatically calculating fees for transactions.

AFAIK, bakers by default adhere to the following fee calculation:

``````fees >= (minimal_fees + minimal_nanotez_per_byte * size + minimal_nanotez_per_gas_unit * gas)
``````

where

``````minimal_fees = 0.000 1ꜩ (100µꜩ)
minimal_nanotez_per_gas_unit = 100nꜩ/gu (0.000 000 1ꜩ/gu)
minimal_nanotez_per_byte = 1000nꜩ/B (0.000 001ꜩ/B)
``````

(Source)

Today, I had a transaction which timed out in the mempool. The transaction used 66754 gas units and 234 bytes of storage.

Based on the above, I think that the proposed fee of 0.00701XTZ should have been sufficient to get included in a block:

``````minimal fees =                     .000001
gas fees     = 66745 * 100nꜩ/gu =  .006676  (rounded up)
storage fees = 234 * 1000nꜩ/B   =  .000234
----------------------------------------------
total        =                     .00701
``````

• If you want to compare, tzkt.io/opP2A3NnAPwioSHfVcjv6B6Vji5HKF6ruRsJyEVUWDk1x8S7Xy5 0.00701 is crazy high for a fee, almost 4x the minimum of 0.001792. I believe the storage minimum is 257. You might want to look for more examples of calling contracts to see what their fees/params are set. Jul 27, 2020 at 14:00
• AFAIK 257 bytes is the fixed cost for origination of a contract. This is simply an invocation. The gas is expensive, which makes sense. This is a multi-contract call that is updating a big map and serialization/deserialization and contract calls are expensive. I was able to send successfully in this transaction: carthage.tzkt.io/… which applied with: gas = 66754 storage = 234 So I believe those values are correct. I just don't know how to back out the actual fee in XTZ from them. Jul 28, 2020 at 1:50
• You don't. Gas doesn't have relationship with the txn fee. forum.tezosagora.org/t/psa-do-not-quote-gas-cost-in-tez/1618 You can specify max gas for every operation and keep the minimum fee and still have success. Gas is just a limiting factor to prevent runaway contracts. Jul 28, 2020 at 14:07
• Okay, so it "technically" doesn't but in practice it does. If this wasn't true, then why did this operation not apply? The same exact operation applied with a higher fee. This operation sat in the mempool for 20+ minutes before I overwrote it. Jul 29, 2020 at 2:28

The `minimal_nanotez_per_byte` refers to the size of the transaction itself when serialized to bytes with a signature.