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.
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
b are specified in protocol paramaters. You can get the latest parameters with Blockfrost using this endpoint:
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
And if you take another look at the protocol parameters, you may notice two other fields:
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
Fee calculation is actually pretty simple.
0.155381 + 0.000044 * size
size is the transaction size in bytes.
You can use TyphonJs NPM library,