<p>For the most part, your wallet software should take care of all this. You should only determine how urgently you need the transaction to be confirmed and pick the feerate, the wallet would take care of the rest. The 88 you mention would likely refer to a feerate of 88 sats/vbyte here, although that sounds like a gross overestimate at the current market conditions.</p>
<p>If you want to manually build a transaction, you need to know a bit more.
Before you build a bitcoin transaction, you know which transaction outputs you are aiming to create. The recipients addresses tell you how much data it'll take to specify each output in the transaction. The transaction header is also mostly constant size, it's 10 bytes for non-segwit transactions and 42 weight units for segwit transactions.<br />
The input side is a bit more complicated, as you usually do not know in advance how many inputs it'll take to fund your transaction. Your wallet may also be able to spend Unspent Transaction Outputs (UTXOs) of various output types which take different amounts of data to include in a transaction.
So, you'll either need to pick the inputs first, then determine their size and calculate the fees, or you can do both in concert, by calculating the cost for each input and deducting in from the UTXO's values before considering them for inclusion.</p>
<p>The actual sizes for some popular output types can be seen in this table: <a href="https://i.sstatic.net/iWulo.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/iWulo.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2021-10-27T14:18:02.710Z
I try to do it with python. So, i know only minimal fee and amount of money.
Clark Devlin
CC BY-SA 4.0
2021-10-27T14:30:06.837Z
The minimal feerate for a transaction to get relayed is 1 sat/vbyte. The estimate on earn.com seems to be off by a factor of 20, so I would suggest that you don't use that.
Murch
CC BY-SA 4.0
2021-10-27T14:14:32.717Z
2021-10-27T14:14:32.717Z
Murch
<p>For Python, may I suggest using the Mempool.space API. You can use their public API or run an instance of their <a href="https://github.com/mempool/mempool" rel="nofollow noreferrer">software locally</a>.</p>
<p>Here's is a <a href="https://github.com/pxsocs/warden/blob/23ae728412e8f74b0763f8ef99eee156e2b44111/warden/api/routes.py#L661" rel="nofollow noreferrer">sample code</a> I've used in the past that should point you in the right direction.</p>

CC BY-SA 4.0
2021-10-27T22:17:47.123Z
2021-10-27T22:17:47.123Z
alphazeta
<p>How can I calculate the correct fees for a blockchain transaction? I use <a href="https://bitcoinfees.earn.com/api/v1/fees/recommended" rel="nofollow noreferrer">https://bitcoinfees.earn.com/api/v1/fees/recommended</a>. I got hourfee - 88. How can i calculate bytes of transaction?</p>

CC BY-SA 4.0
2021-10-27T15:42:59.940Z
Corollary, the Earn.com fee estimates flatlined almost a year ago: https://twitter.com/murchandamus/status/1453367595076407298. You should use something else.
Murch
CC BY-SA 4.0
2021-10-27T18:19:58.577Z
@Murch ty. so. what should i do?
Clark Devlin
CC BY-SA 4.0
2021-10-27T18:45:28.493Z
You should pick a better source for feerate estimates, e.g. https://mempool.space/api/v1/fees/recommended perhaps?
Murch
<transaction-fees>
How can I calculate the correct fees for a blockchain transaction?
Clark Devlin
# How can I calculate the correct fees for a blockchain transaction?

(Asked by: username_0 on 2021-10-27)

How can I calculate the correct fees for a blockchain transaction? I use <https://bitcoinfees.earn.com/api/v1/fees/recommended>. I got hourfee - 88. How can i calculate bytes of transaction?

**Tags:** transaction-fees

> **Comments:**
> **username_1**: Corollary, the Earn.com fee estimates flatlined almost a year ago: https://twitter.com/murchandamus/status/1453367595076407298. You should use something else.  
> **username_0**: @username_1 ty. so. what should i do?  
> **username_1**: You should pick a better source for feerate estimates, e.g. https://mempool.space/api/v1/fees/recommended perhaps?  

---

## 2 answers

### Answer by username_1 on 2021-10-27. Score: 0

For the most part, your wallet software should take care of all this. You should only determine how urgently you need the transaction to be confirmed and pick the feerate, the wallet would take care of the rest. The 88 you mention would likely refer to a feerate of 88 sats/vbyte here, although that sounds like a gross overestimate at the current market conditions.

If you want to manually build a transaction, you need to know a bit more.
Before you build a bitcoin transaction, you know which transaction outputs you are aiming to create. The recipients addresses tell you how much data it'll take to specify each output in the transaction. The transaction header is also mostly constant size, it's 10 bytes for non-segwit transactions and 42 weight units for segwit transactions.  
The input side is a bit more complicated, as you usually do not know in advance how many inputs it'll take to fund your transaction. Your wallet may also be able to spend Unspent Transaction Outputs (UTXOs) of various output types which take different amounts of data to include in a transaction.
So, you'll either need to pick the inputs first, then determine their size and calculate the fees, or you can do both in concert, by calculating the cost for each input and deducting in from the UTXO's values before considering them for inclusion.

The actual sizes for some popular output types can be seen in this table: [![enter image description here](https://i.sstatic.net/iWulo.png)](https://i.sstatic.net/iWulo.png)

> **Comments:**
> **username_0**: I try to do it with python. So, i know only minimal fee and amount of money.  
> **username_1**: The minimal feerate for a transaction to get relayed is 1 sat/vbyte. The estimate on earn.com seems to be off by a factor of 20, so I would suggest that you don't use that.  

---

### Answer by username_2 on 2021-10-27. Score: 0

For Python, may I suggest using the Mempool.space API. You can use their public API or run an instance of their [software locally](https://github.com/mempool/mempool).

Here's is a [sample code](https://github.com/pxsocs/warden/blob/23ae728412e8f74b0763f8ef99eee156e2b44111/warden/api/routes.py#L661) I've used in the past that should point you in the right direction.


---

