<p>You do not need to calculate previous transaction hash, because it is already known. 
To spend the previous output you just have to know</p>

<ul>
<li>tx hash</li>
<li>output index in this tx</li>
<li>output value</li>
<li>output script</li>
</ul>

<p>plus you should choose</p>

<ul>
<li>fee</li>
<li>new address</li>
</ul>

<p>then create some byte data and sign it with appropriate private key </p>

<p>Good manual you can find here: <a href="https://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx">How to redeem a basic Tx?</a></p>

CC BY-SA 3.0
2014-07-31T15:26:54.147Z
2014-07-31T15:26:54.147Z
2017-04-13T12:47:33.743Z
amaclin
<p>You hash the header.  Format is here: <a href="https://en.bitcoin.it/wiki/Block_hashing_algorithm" rel="nofollow">https://en.bitcoin.it/wiki/Block_hashing_algorithm</a>
The body contains the transactions.
Here's the Bitcoin transaction format:
<a href="https://en.bitcoin.it/wiki/Transactions" rel="nofollow">https://en.bitcoin.it/wiki/Transactions</a></p>

CC BY-SA 3.0
2014-07-31T15:12:16.450Z
2014-07-31T15:12:16.450Z
juhraffe
<p>Can anyone provide a clear example on how to calculate a previous transaction hash?</p>

<p>Say I want to create a new transaction, I get that the hash is calculated by doubling <code>sha256</code> a message <strong>m</strong>, but I'm having a hard time understanding the structure of <strong>m</strong>.</p>

<transactions><client><spending>
How is the previous transaction hash calculated?
Mohamed Amine
# How is the previous transaction hash calculated?

(Asked by: username_0 on 2014-07-31)

Can anyone provide a clear example on how to calculate a previous transaction hash?

Say I want to create a new transaction, I get that the hash is calculated by doubling `sha256` a message **m**, but I'm having a hard time understanding the structure of **m**.

**Tags:** transactions, client, spending


---

## 2 answers

### Answer by username_1 on 2014-07-31. Score: 2

You do not need to calculate previous transaction hash, because it is already known.
To spend the previous output you just have to know

* tx hash
* output index in this tx
* output value
* output script

plus you should choose

* fee
* new address

then create some byte data and sign it with appropriate private key

Good manual you can find here: [How to redeem a basic Tx?](https://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx)


---

### Answer by username_2 on 2014-07-31. Score: 0

You hash the header. Format is here: <https://en.bitcoin.it/wiki/Block_hashing_algorithm>
The body contains the transactions.
Here's the Bitcoin transaction format:
<https://en.bitcoin.it/wiki/Transactions>


---

