TXID
The hash of a transaction's data.
A TXID
(Transaction ID) is basically an identification number for a bitcoin transaction.
Examples:
f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16
- First ever Bitcoin transaction to Hal Finney in 2010.a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d
- Pizza transaction for 10,000 BTC in 2010.4ce18f49ba153a51bcda9bb80d7f978e3de6e81b5fc326f00465464530c052f4
- The transaction containing the first donation I received for making this website.
A TXID
is always 32 bytes (64 characters) and hexadecimal.
Creating a TXID
You get a TXID
by hashing transaction data through SHA256 twice.
0100000001c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704000000004847304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901ffffffff0200ca9a3b00000000434104ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84cac00286bee0000000043410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac00000000
169e1e83e930853391bc6f35f605c6754cfead57cf8387639d3b4096c54f18f4
(Note: reverse the byte order first if you want to find this transaction in the blockchain…)
Searching for TXIDs in the blockchain.
If you’ve just hashed some transaction data and want to search for a TXID in the blockchain, you have to search for it in reverse byte order.
txid (original): 169e1e83e930853391bc6f35f605c6754cfead57cf8387639d3b4096c54f18f4
txid (searching): f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16
Why?
Because welcome to Bitcoin.
Due to historical accident, the tx and block hashes that bitcoin core uses are byte-reversed. I’m not entirely sure why. May be something like using openssl bignum to store hashes or something like that, then printing them as a number. – Wladimir van der Laan (Bitcoin Core developer)
In other words, this was a slight oversight in the early development of Bitcoin that has now become a standard.
Where are TXIDs used?
1. Searching the blockchain.
If you’ve just made a transaction, you can use the TXID
to find it in the blockchain. For example:
bitcoin-cli getrawtransaction 0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098

If you have been given a TXID
by your bitcoin wallet, it’s probably already in its “searchable” format (reverse byte order).
2. Spending outputs.
You use a TXID
when you want to use an existing output as an input in a new transaction.
txid
it was created in, along with the vout
number for that transaction.Because after all, a TXID
is a unique identifier1 for a transaction.
Notes
Hash functions like SHA256 are great for creating identification numbers, because they will take in any string of data and always spit out a short yet unique result.
Coinbase transactions having the same TXID.
There has been a situation where two “different” coinbase transactions had the same TXID.
These coinbase transactions used the same address
when claiming the block reward from two different blocks. This meant that their transaction data was the same, and so the TXIDs were the same also. Here are the transactions and the blocks they were included in:
e3bf3d07d4b0375638d5f1db5255fe07ba2c4cb067cd81b84ee974b6585fb468
d5d27987d2a3dfc724e359870c6644b40e497bdc0589a033220fe15429d88599
The Fix.
Initially, BIP 30 introduced a rule that prevented blocks from containing a TXID that already exists. Later, BIP 34 required coinbase transactions to include the height of the block they were mining in to their transaction data, so that coinbase transactions could be different.
Links
- https://github.com/bitpay/insight-api/issues/42
- http://bitcoin.stackexchange.com/questions/3030/two-blocks-two-transactions-same-hash
- http://bitcoin.stackexchange.com/questions/11999/can-the-outputs-of-transactions-with-duplicate-hashes-be-spent/
Thanks to DJBunnies for pointing this out to me.