<p>TXIDs have <a href="https://bitcoin.org/en/developer-reference#hash-byte-order" rel="nofollow noreferrer">two forms</a>; the form used internally for outpoints and merkle leaves (internal byte order), and the form used in RPC calls and block explorers (RPC byte order).  These are often called, respectivey, little-endian byte order and big-endian byte order (although those descriptions aren't quite accurate).</p>

<p>Here's python code from the <a href="https://bitcoin.org/en/developer-reference#hash-byte-order" rel="nofollow noreferrer">Bitcoin.org Developer Documentation</a> generating both forms for the TXID for the transaction in your question:</p>

<pre><code>#!/usr/bin/env python

from sys import byteorder
from hashlib import sha256

## You can put in $data an 80-byte block header to get its header hash,
## or a raw transaction to get its txid
data = "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d014dffffffff0100f2052a01000000434104e70a02f5af48a1989bf630d92523c9d14c45c75f7d1b998e962bff6ff9995fc5bdb44f1793b37495d80324acba7c8f537caaf8432b8d47987313060cc82d8a93ac00000000".decode("hex")
hash = sha256(sha256(data).digest()).digest()

print "Warning: this code only tested on a little-endian x86_64 arch"
print
print "System byte order:", byteorder
print "Internal-Byte-Order Hash: ", hash.encode('hex_codec')
print "RPC-Byte-Order Hash:      ", hash[::-1].encode('hex_codec')
</code></pre>

<p>And here's the output:</p>

<pre><code>Warning: this code only tested on a little-endian x86_64 arch

System byte order: little
Internal-Byte-Order Hash:  660802c98f18fd34fd16d61c63cf447568370124ac5f3be626c2e1c3c9f0052d
RPC-Byte-Order Hash:       2d05f0c9c3e1c226e63b5fac240137687544cf631cd616fd34fd188fc9020866
</code></pre>

<p>The internal byte order used by the Bitcoin is in fact <strong>Little-Endian</strong>, while the RPC byte order is <strong>Big-Endian</strong>. For details explaining how this works refer <a href="http://learnmeabitcoin.com/glossary/little-endian" rel="nofollow noreferrer">this link</a>.</p>

CC BY-SA 4.0
2014-11-28T16:21:10.437Z
2018-12-02T03:52:58.133Z
2018-12-02T03:52:58.133Z
David A. Harding
<p>I'm trying to parse a bitcoin block using Python.</p>

<p>I called getrawtransaction over JSON-RPC. I got this:</p>

<p>01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d014dffffffff0100f2052a01000000434104e70a02f5af48a1989bf630d92523c9d14c45c75f7d1b998e962bff6ff9995fc5bdb44f1793b37495d80324acba7c8f537caaf8432b8d47987313060cc82d8a93ac00000000</p>

<p>How do I calculate the txid of this raw transaction?</p>

<sha256><transaction-id>
How do I calculate the txid of this raw transaction?
user21322
# How do I calculate the txid of this raw transaction?

(Asked by: username_0 on 2014-11-28)

I'm trying to parse a bitcoin block using Python.

I called getrawtransaction over JSON-RPC. I got this:

01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d014dffffffff0100f2052a01000000434104e70a02f5af48a1989bf630d92523c9d14c45c75f7d1b998e962bff6ff9995fc5bdb44f1793b37495d80324acba7c8f537caaf8432b8d47987313060cc82d8a93ac00000000

How do I calculate the txid of this raw transaction?

**Tags:** sha256, transaction-id


---

## 1 answers

### Answer by username_1 on 2014-11-28. Score: 5 | Accepted answer

TXIDs have [two forms](https://bitcoin.org/en/developer-reference#hash-byte-order); the form used internally for outpoints and merkle leaves (internal byte order), and the form used in RPC calls and block explorers (RPC byte order). These are often called, respectivey, little-endian byte order and big-endian byte order (although those descriptions aren't quite accurate).

Here's python code from the [Bitcoin.org Developer Documentation](https://bitcoin.org/en/developer-reference#hash-byte-order) generating both forms for the TXID for the transaction in your question:

```
#!/usr/bin/env python

from sys import byteorder
from hashlib import sha256

## You can put in $data an 80-byte block header to get its header hash,
## or a raw transaction to get its txid
data = "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d014dffffffff0100f2052a01000000434104e70a02f5af48a1989bf630d92523c9d14c45c75f7d1b998e962bff6ff9995fc5bdb44f1793b37495d80324acba7c8f537caaf8432b8d47987313060cc82d8a93ac00000000".decode("hex")
hash = sha256(sha256(data).digest()).digest()

print "Warning: this code only tested on a little-endian x86_64 arch"
print
print "System byte order:", byteorder
print "Internal-Byte-Order Hash: ", hash.encode('hex_codec')
print "RPC-Byte-Order Hash:      ", hash[::-1].encode('hex_codec')

```

And here's the output:

```
Warning: this code only tested on a little-endian x86_64 arch

System byte order: little
Internal-Byte-Order Hash:  660802c98f18fd34fd16d61c63cf447568370124ac5f3be626c2e1c3c9f0052d
RPC-Byte-Order Hash:       2d05f0c9c3e1c226e63b5fac240137687544cf631cd616fd34fd188fc9020866

```

The internal byte order used by the Bitcoin is in fact **Little-Endian**, while the RPC byte order is **Big-Endian**. For details explaining how this works refer [this link](http://learnmeabitcoin.com/glossary/little-endian).


---

