I realize that the CLI has commands for calculating a minimum fee based on a transaction size, but I'm wanting to do a calculation manually. The documentation states that the formula for calculating the transaction minimum fee is a * size(tx) + b where a & b are protocol parameters, and size(tx) is the transaction size in bytes.

Is there a way to calculate the transaction size if I know the number of consumed and output UTxOs? Also, are a and b in the genesis file?


The a and b fees parameters are protocol parameters, so you should probably check the current epoch, even they are unlikely to change suddenly.

$ curl -s  -H "project_id: $BLOCKFROST_PROJECT_ID" https://cardano-mainnet.blockfrost.io/api/v0/epochs/latest/parameters | jq '. | .min_fee_a, .min_fee_b'

Then, all your need to do to calculate your fees is:

a + b × size (in bytes)

Read more on docs.cardano.org.

  • To get the exact size in bytes, you're going to want to build the transaction and include a dummy value for the fee even though you don't know it yet. Then you can get the exact number of bytes the transaction will take instead of doing estimates based on UTxO counts and such. Then, just calculate as @Marek showed and re-build the Tx a second time with the exact fees. Aug 30 '21 at 20:04
  • Thanks, you've both been helpful. I guess I probably also wasn't perfectly clear. I'm trying to figure out how to get the size(tx) value. I was wandering if I could do it without the CLI? I'm assuming its not the size of the ASCII characters in bytes but formatted differently. I couldn't find the exact info in the docs (although I'm sure its there somewhere).
    – nalyd88
    Aug 30 '21 at 23:18
  • Thanks Marek, I forgot to check the protocol parameters file. I was looking in the genesis files but of course it can change!
    – nalyd88
    Aug 31 '21 at 2:41
  • @nalyd88 The only way to get the size of the transaction without using cardano-cli is to build the cbor for everything yourself. I do this with my firehose project, but it's quite involved. Even cardano-cli doesn't give you exactly the minfee value. It just does a best guess estimate and pads it a bit. Things like stake vs enterprise output addresses can change the size of cbor and affect fees. Sep 22 '21 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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