2

Is there a way to calculate transaction fees without having to go through cardano-cli? Maybe something like Blockfrost? or any other API providers? I don't want to run a local node to do that.

2
  • If you don't want to run a local node, how are you expecting to submit the transaction? The normal way of doing this is to use cardano-cli to first calculate the free and then use it to submit the transaction. Aug 10 at 3:11
  • @ErikdeCastroLopo, I intend to submit it via Blockfrost.
    – Attilah
    Aug 10 at 3:40

3 Answers 3

2

Transaction fees are computed based on two factors: size of the transactions, and required resources (memory and CPU steps).

As Melroy van den Berg mentioned, transaction size increases the fee linearly:

fee_for_size = a * size(tx) + b

Both a and b are specified in protocol paramaters. You can get the latest parameters with Blockfrost using this endpoint:

/epochs/latest/parameters

min_fee_a is the coefficient, while min_fee_b is the constant.

Blockfrost also provides another endpoint for finding the required resources for a given transaction (I don't remember the exact names used in its response, but let's call them memory and steps).

And if you take another look at the protocol parameters, you may notice two other fields: price_mem and price_step. These are, respectively, price increases per memory and cpu steps. Therefore, you can compute your final transaction fee:

fee = fee_for_size + fee_for_execution

where:
fee_for_size      = a * size(tx) + b
fee_for_execution = memory * price_mem + steps * price_step
0

Fee calculation is actually pretty simple.

0.155381 + 0.000044 * size

Where size is the transaction size in bytes.

More info

2
  • 1
    This does not include the Smart Contract fee. The values you used are also subject to change, Aug 10 at 3:10
  • answer could be improved by explaining where those numbers come from and be linking the documentation of that process. This way users can set your comment as an answer
    – Nic_T2H
    Aug 12 at 17:22
0

You can use TyphonJs NPM library,

https://docs.strica.io/lib/typhonjs/classes/Transaction.html#getFee

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.