<p>You have to look up the previous unspent transaction output using the hash and txout-index, and this output contains the amount in satoshis which is provided in entirety as input for the transaction. </p>

CC BY-SA 4.0
2020-04-11T23:19:10.550Z
2020-04-11T23:19:10.550Z
Mark H
<p>I am attempting to calculate the mining fee of a transaction, given it's unsigned transaction hex by taking difference between the sum of the inputs and outputs.</p>

<p>I also have access to an array of <code>Txout</code> and <code>Txin</code> blobs.</p>

<p>Taking the sum of the the <code>Txout</code> array is easy, as first eight bytes is the value of the output, but I do not know how to get the value of an input for a <code>Txin</code>. </p>

<p>The format of the <code>Txin</code> blobs is that which is described on the <a href="https://en.bitcoin.it/wiki/Transaction#General_format_.28inside_a_block.29_of_each_input_of_a_transaction_-_Txin" rel="nofollow noreferrer">bitcoin.it</a> wiki --</p>

<pre><code>Previous Transaction hash   ||  32 bytes
Previous Txout-index        || 4 bytes
Txin-script                 || 1-9 bytes
Txin-script                 || arbitrary number of bytes
sequence_no                 ||  4 bytes
</code></pre>

<p>How can I get the value of each input?</p>

<raw-transaction><transaction-input>
How do I calculate the sum of transaction inputs?
user104928
# How do I calculate the sum of transaction inputs?

(Asked by: username_0 on 2020-04-11)

I am attempting to calculate the mining fee of a transaction, given it's unsigned transaction hex by taking difference between the sum of the inputs and outputs.

I also have access to an array of `Txout` and `Txin` blobs.

Taking the sum of the the `Txout` array is easy, as first eight bytes is the value of the output, but I do not know how to get the value of an input for a `Txin`.

The format of the `Txin` blobs is that which is described on the [bitcoin.it](https://en.bitcoin.it/wiki/Transaction#General_format_.28inside_a_block.29_of_each_input_of_a_transaction_-_Txin) wiki --

```
Previous Transaction hash   ||  32 bytes
Previous Txout-index        || 4 bytes
Txin-script                 || 1-9 bytes
Txin-script                 || arbitrary number of bytes
sequence_no                 ||  4 bytes

```

How can I get the value of each input?

**Tags:** raw-transaction, transaction-input


---

## 1 answers

### Answer by username_1 on 2020-04-11. Score: 2 | Accepted answer

You have to look up the previous unspent transaction output using the hash and txout-index, and this output contains the amount in satoshis which is provided in entirety as input for the transaction.


---

