<p>0) read <a href="https://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx">How to redeem a basic Tx?</a></p>

<p>1) take your transaction as array of bytes</p>

<p>2) replace all input scrips to empty scrips</p>

<p>3) replace one input script to original "OP_DUP OP_HASH160..."</p>

<p>4) append "hash code type" SIGHASH_ALL</p>

<p>5) take sha256 ( sha256 ( data ) )</p>

<p>that's all</p>

<p>Have a look on my code</p>

<pre><code>const MyKey32 Transaction::getRawHash ( const int n, const QByteArray&amp; scr ) const
{
  MyByteArray ret;                                    // create empty array
  Stream stream ( s );
  ret.putInt32 ( stream.readU32 ( ) );                // version
  ret.putVarInt ( stream.readVar ( ) );               // input count
  for ( int i ( 0 ); i &lt; inputs; i++ )                // copy all inputs
  {
    ret.append ( stream.readHash ( ) );
    ret.putInt32 ( stream.readU32 ( ) );
    stream.skipVarData ( );                            // skip original script
    ret.putPrefixed ( i == n ? scr : QByteArray ( ) ); // !!! script replacement
    ret.putInt32 ( stream.readU32 ( ) );
  }
  ret.putVarInt ( stream.readVar ( ) );                // output count
  for ( int i ( 0 ); i &lt; outputs; i++ )                // copy all outputs byte-by-byte
  {
    ret.putInt64 ( stream.readU64 ( ) );
    ret.putPrefixed ( stream.readVarData ( ) );
  }
  ret.putInt32 ( stream.readU32 ( ) );                 // lock
  ret.putInt32 ( SIGHASH_ALL );                        // !!! append hashcode
  return MyKey32 ( ret.constData ( ), ret.size ( ) );  // create hash256 of array
}
</code></pre>

CC BY-SA 3.0
2014-05-17T06:33:40.493Z
That helps me somewhat, but an example of an existing transaction would enable me (and others I'd assume) to understand it best.  Also, are you sure that that results in what is referred to as the "Z" value in the equation?
Mine
CC BY-SA 3.0
2014-05-19T04:15:38.040Z
Yes, I am sure that this method works. This is a part of a program which looks for compromised private keys. The results (not recent) are here https://bitcointalk.org/index.php?topic=461351.msg6408633#msg6408633 () I can help you more but not for free.
amaclin
CC BY-SA 3.0
2014-11-19T02:38:16.893Z
Is there, by chance, a website I could simply paste something into and it'll give me this hash?  Too many steps to this process are currently beyond me.
Mine
CC BY-SA 3.0
2014-05-16T13:22:04.953Z
2014-05-16T13:22:04.953Z
2017-04-13T12:47:32.940Z
amaclin
<p>I get it that the "OP_CHECKSIG" does this, but I can't see how to recreate it.  I tried SHA1 and SHA256 of some of the info in a given bitcoin transaction but it didn't give me confirmed values of Z.  Can someone please select a transaction, tell me which one it is and show me what I need to cut and paste into a SHA1 calculator to get the actual Z value?</p>

<p>The hash value of TX 9ec4bc49e828d924af1d1029cacf709431abbde46d59554b62bc270e3b29c4b1 is supposed to be z = c0e2d0a89a348de88fda08211c70d1d7e52ccef2eb9459911bf977d587784c6e
and also z = 17b0f41c8c337ac1e18c98759e83a8cccbc368dd9d89e5f03cb633c265fd0ddc but I do not see how the z values are achieved.</p>

<transactions><protocol><ecdsa>
How to get the Z value aka Hash of the outputs to be signed
Mine
# How to get the Z value aka Hash of the outputs to be signed

(Asked by: username_0 on 2014-05-16)

I get it that the "OP\_CHECKSIG" does this, but I can't see how to recreate it. I tried SHA1 and SHA256 of some of the info in a given bitcoin transaction but it didn't give me confirmed values of Z. Can someone please select a transaction, tell me which one it is and show me what I need to cut and paste into a SHA1 calculator to get the actual Z value?

The hash value of TX 9ec4bc49e828d924af1d1029cacf709431abbde46d59554b62bc270e3b29c4b1 is supposed to be z = c0e2d0a89a348de88fda08211c70d1d7e52ccef2eb9459911bf977d587784c6e
and also z = 17b0f41c8c337ac1e18c98759e83a8cccbc368dd9d89e5f03cb633c265fd0ddc but I do not see how the z values are achieved.

**Tags:** transactions, protocol, ecdsa


---

## 1 answers

### Answer by username_1 on 2014-05-16. Score: 1

0) read [How to redeem a basic Tx?](https://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx)

1) take your transaction as array of bytes

2) replace all input scrips to empty scrips

3) replace one input script to original "OP\_DUP OP\_HASH160..."

4) append "hash code type" SIGHASH\_ALL

5) take sha256 ( sha256 ( data ) )

that's all

Have a look on my code

```
const MyKey32 Transaction::getRawHash ( const int n, const QByteArray& scr ) const
{
  MyByteArray ret;                                    // create empty array
  Stream stream ( s );
  ret.putInt32 ( stream.readU32 ( ) );                // version
  ret.putVarInt ( stream.readVar ( ) );               // input count
  for ( int i ( 0 ); i < inputs; i++ )                // copy all inputs
  {
    ret.append ( stream.readHash ( ) );
    ret.putInt32 ( stream.readU32 ( ) );
    stream.skipVarData ( );                            // skip original script
    ret.putPrefixed ( i == n ? scr : QByteArray ( ) ); // !!! script replacement
    ret.putInt32 ( stream.readU32 ( ) );
  }
  ret.putVarInt ( stream.readVar ( ) );                // output count
  for ( int i ( 0 ); i < outputs; i++ )                // copy all outputs byte-by-byte
  {
    ret.putInt64 ( stream.readU64 ( ) );
    ret.putPrefixed ( stream.readVarData ( ) );
  }
  ret.putInt32 ( stream.readU32 ( ) );                 // lock
  ret.putInt32 ( SIGHASH_ALL );                        // !!! append hashcode
  return MyKey32 ( ret.constData ( ), ret.size ( ) );  // create hash256 of array
}

```

> **Comments:**
> **username_0**: That helps me somewhat, but an example of an existing transaction would enable me (and others I'd assume) to understand it best.  Also, are you sure that that results in what is referred to as the "Z" value in the equation?  
> **username_1**: Yes, I am sure that this method works. This is a part of a program which looks for compromised private keys. The results (not recent) are here https://bitcointalk.org/index.php?topic=461351.msg6408633#msg6408633 () I can help you more but not for free.  
> **username_0**: Is there, by chance, a website I could simply paste something into and it'll give me this hash?  Too many steps to this process are currently beyond me.  

---

