<p>you will find more details ( and less technical than pseudocode ) concerning the fee structure on : <a href="https://en.bitcoin.it/wiki/Transaction_fees" rel="nofollow">https://en.bitcoin.it/wiki/Transaction_fees</a>
 see also <a href="https://en.bitcoin.it/wiki/Free_transaction_relay_policy" rel="nofollow">https://en.bitcoin.it/wiki/Free_transaction_relay_policy</a></p>

CC BY-SA 3.0
2011-12-17T16:27:59.963Z
Those links have no information at all about what was asked in the question.
Meni Rosenfeld
CC BY-SA 3.0
2011-12-17T04:07:53.713Z
2012-03-02T03:48:03.077Z
2012-03-02T03:48:03.077Z
neofutur
<p>This isn't possible with just the message.</p>

CC BY-SA 3.0
2012-03-07T04:06:07.407Z
... because the fee is simply the difference between the sum of the inputs and the sum of the outputs, and the transaction message doesn't specify the value of the inputs.  It only provides hashes and output numbers of the transactions which provide the inputs, and so we need access to those transaction messages too.  Is that what you meant?
Chris Moore
CC BY-SA 3.0
2012-03-05T22:10:56.260Z
2012-03-05T22:10:56.260Z
Luke Dashjr
<p>Use the following pseudocode:</p>

<pre><code>TotalOutputValue = 0
For each Output in tx_out array
  TotalOutputValue += Output[value]
TotalInputValue = 0
For each Input in tx_in array
  PreviousOutput = Input[previous_output]
  PreviousTransaction = PreviousOutput[hash]
  OutputIndex = PreviousOutput[index]
  Look up the transaction with hash PreviousTransaction
  Output = The output with index OutputIndex in that transaction
  TotalInputValue += Output[value]
Fee = TotalInputValue - TotalOutputValue
</code></pre>

CC BY-SA 3.0
2011-12-15T19:33:35.573Z
2011-12-15T19:33:35.573Z
Meni Rosenfeld
<p>Given a <a href="https://en.bitcoin.it/wiki/Protocol_specification#tx">Tx message</a>, how does one calculate how big a fee one paid for the transaction?</p>

<transactions><protocol>
Given a Tx message, how does one calculate the fee paid for the transaction?
ThePiachu
# Given a Tx message, how does one calculate the fee paid for the transaction?

(Asked by: username_0 on 2011-12-15)

Given a [Tx message](https://en.bitcoin.it/wiki/Protocol_specification#tx), how does one calculate how big a fee one paid for the transaction?

**Tags:** transactions, protocol


---

## 3 answers

### Answer by username_2 on 2011-12-15. Score: 5 | Accepted answer

Use the following pseudocode:
TotalOutputValue = 0
For each Output in tx_out array
  TotalOutputValue += Output[value]
TotalInputValue = 0
For each Input in tx_in array
  PreviousOutput = Input[previous_output]
  PreviousTransaction = PreviousOutput[hash]
  OutputIndex = PreviousOutput[index]
  Look up the transaction with hash PreviousTransaction
  Output = The output with index OutputIndex in that transaction
  TotalInputValue += Output[value]
Fee = TotalInputValue - TotalOutputValue


---

### Answer by username_1 on 2011-12-17. Score: 0

you will find more details ( and less technical than pseudocode ) concerning the fee structure on : <https://en.bitcoin.it/wiki/Transaction_fees>
see also <https://en.bitcoin.it/wiki/Free_transaction_relay_policy>

> **Comments:**
> **username_2**: Those links have no information at all about what was asked in the question.  

---

### Answer by username_3 on 2012-03-05. Score: -1

This isn't possible with just the message.

> **Comments:**
> **username_4**: ... because the fee is simply the difference between the sum of the inputs and the sum of the outputs, and the transaction message doesn't specify the value of the inputs.  It only provides hashes and output numbers of the transactions which provide the inputs, and so we need access to those transaction messages too.  Is that what you meant?  

---

