<p>Transaction fees are computed based on two factors: size of the transactions, and required resources (memory and CPU steps).</p>
<p><a href="https://cardano.stackexchange.com/a/8844/7225">As Melroy van den Berg mentioned</a>, transaction size increases the fee linearly:</p>
<pre><code>fee_for_size = a * size(tx) + b
</code></pre>
<p>Both <code>a</code> and <code>b</code> are specified in <em>protocol paramaters</em>. You can get the latest parameters with Blockfrost using <a href="https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/%7E1epochs%7E1%7Bnumber%7D%7E1parameters/get" rel="nofollow noreferrer">this endpoint</a>:</p>
<pre><code>/epochs/latest/parameters
</code></pre>
<p><code>min_fee_a</code> is the coefficient, while <code>min_fee_b</code> is the constant.</p>
<p>Blockfrost also provides <a href="https://docs.blockfrost.io/#tag/Cardano-Utilities/paths/%7E1utils%7E1txs%7E1evaluate/post" rel="nofollow noreferrer">another endpoint</a> 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 <code>memory</code> and <code>steps</code>).</p>
<p>And if you <a href="https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/%7E1epochs%7E1%7Bnumber%7D%7E1parameters/get" rel="nofollow noreferrer">take another look at the protocol parameters</a>, you may notice two other fields: <code>price_mem</code> and <code>price_step</code>. These are, respectively, price increases per memory and cpu steps. Therefore, you can compute your final transaction fee:</p>
<pre><code>fee = fee_for_size + fee_for_execution

where:
fee_for_size      = a * size(tx) + b
fee_for_execution = memory * price_mem + steps * price_step
</code></pre>

CC BY-SA 4.0
2022-11-06T16:51:22.700Z
This only applies if you know your execution units. To find them out, you might want to use Blockfrost endpoint https://docs.blockfrost.io/#tag/Cardano-Utilities/paths/~1utils~1txs~1evaluate/post
Marek Mahut - StakeNuts
CC BY-SA 4.0
2022-09-09T12:23:38.773Z
2022-09-09T12:23:38.773Z
keyanm
<p>Fee calculation is actually pretty simple.</p>
<p><code>0.155381 + 0.000044 * size</code></p>
<p>Where <code>size</code> is the transaction size in bytes.</p>
<p><a href="https://docs.cardano.org/explore-cardano/fee-structure" rel="nofollow noreferrer">More info</a></p>

CC BY-SA 4.0
2022-08-10T03:10:40.927Z
This does not include the Smart Contract fee. The values you used are also subject to change,
Erik de Castro Lopo
CC BY-SA 4.0
2022-08-12T17:22:54.197Z
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
CC BY-SA 4.0
2022-08-10T02:19:22.753Z
2022-08-10T02:19:22.753Z
Melroy van den Berg
<p>You can use TyphonJs NPM library,</p>
<p><a href="https://docs.strica.io/lib/typhonjs/classes/Transaction.html#getFee" rel="nofollow noreferrer">https://docs.strica.io/lib/typhonjs/classes/Transaction.html#getFee</a></p>

CC BY-SA 4.0
2022-08-10T06:22:19.920Z
2022-08-10T06:22:19.920Z
Prashanth S.
<p>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.</p>

CC BY-SA 4.0
2022-08-10T03:11:28.870Z
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.
Erik de Castro Lopo
CC BY-SA 4.0
2022-08-10T03:40:23.607Z
@ErikdeCastroLopo, I intend to submit it via Blockfrost.
Attilah
<plutus><haskell><blockfrost><fee>
Calculate tx fees via Blockfrost or any other provider?
# Calculate tx fees via Blockfrost or any other provider?

(Asked by: username_0 on 2022-08-10)

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.

**Tags:** plutus, haskell, blockfrost, fee
> **Comments:**
> **username_1**: 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.  
> **username_0**: @ErikdeCastroLopo, I intend to submit it via Blockfrost.  

---

## 3 answers

### Answer by username_2 on 2022-09-09. Score: 3

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

> **Comments:**
> **username_3**: This only applies if you know your execution units. To find them out, you might want to use Blockfrost endpoint https://docs.blockfrost.io/#tag/Cardano-Utilities/paths/~1utils~1txs~1evaluate/post  

---

### Answer by username_4 on 2022-08-10. Score: 0

Fee calculation is actually pretty simple.

`0.155381 + 0.000044 * size`

Where `size` is the transaction size in bytes.

[More info](https://docs.cardano.org/explore-cardano/fee-structure)

> **Comments:**
> **username_1**: This does not include the Smart Contract fee. The values you used are also subject to change,  
> **username_5**: 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  

---

### Answer by username_6 on 2022-08-10. Score: -1

You can use TyphonJs NPM library,

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


---

