<p>Bitcoin core stores the data in the network format for <a href="https://en.bitcoin.it/wiki/Protocol_documentation#block" rel="nofollow noreferrer">blocks</a> and for the <a href="https://en.bitcoin.it/wiki/Protocol_documentation#tx" rel="nofollow noreferrer">transactions</a> in those blocks.</p>
<hr />
<p>Here's an example</p>
<p>Block 170 contains the first transaction other than coinbase transactions. In it Satoshi Nakamoto paid Hal Finney 10 BTC. This was the first time one person paid another person in Bitcoin.</p>
<p>Since the data is in binary, we must use a printable representation of it to make it viewable in this web-page. I choose hexadecimal:</p>
<pre><code>0100000001c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25
857fcd3704000000004847304402204e45e16932b8af514961a1d3a1a25fdf3f
4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd1290
9d831cc56cbbac4622082221a8768d1d0901ffffffff0200ca9a3b0000000043
4104ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa2
8414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6c
d84cac00286bee0000000043410411db93e1dcdb8a016b49840f8c53bc1eb68a
382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b
64f9d4c03f999b8643f656b412a3ac00000000
</code></pre>
<p>Some weeks ago I thought it would be neat to work out by hand what that meant. here's how far I got before losing interest:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Hex Data</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>01000000</code></td>
<td>Version 1 (little endian uint32)</td>
</tr>
<tr>
<td><code>01</code></td>
<td>Number of transaction inputs (compact-int)</td>
</tr>
<tr>
<td>First input</td>
<td></td>
</tr>
<tr>
<td><code>c997a5e56e104102</code> <code>fa209c6a852dd906</code> <code>60a20b2d9c352423</code> <code>edce25857fcd3704</code></td>
<td>Hash of referenced transaction (32 octets)</td>
</tr>
<tr>
<td><code>00000000</code></td>
<td>index of output in referenced transaction (uint32)</td>
</tr>
<tr>
<td><code>48</code></td>
<td>length of unlocking script (compact-int). 48 hex is 72 decimal.</td>
</tr>
<tr>
<td><code>47304402204e45e1</code> <code>6932b8af514961a1</code> <code>d3a1a25fdf3f4f77</code> <code>32e9d624c6c61548</code> <code>ab5fb8cd41022018</code> <code>1522ec8eca07de48</code> <code>60a4acdd12909d83</code> <code>1cc56cbbac462208</code> <code>2221a8768d1d0901</code></td>
<td>unlocking script (72 octets)</td>
</tr>
<tr>
<td><code>ffffffff</code></td>
<td>sequence</td>
</tr>
<tr>
<td><code>02</code></td>
<td>Number of outputs</td>
</tr>
<tr>
<td>First output</td>
<td></td>
</tr>
<tr>
<td><code>00ca9a3b00000000</code></td>
<td>amount 1000000000 satoshi i.e. 10 BTC (int64)</td>
</tr>
<tr>
<td><code>43</code></td>
<td>length of locking script</td>
</tr>
<tr>
<td><code>4104ae1a62fe09c5</code> <code>f51b13905f07f06b</code> <code>99a2f7159b2225f3</code> <code>74cd378d71302fa2</code> <code>8414e7aab37397f5</code> <code>54a7df5f142c21c1</code> <code>b7303b8a0626f1ba</code> <code>ded5c72a704f7e6c</code> <code>d84cac</code></td>
<td>locking script</td>
</tr>
<tr>
<td>Second output</td>
<td></td>
</tr>
<tr>
<td><code>00286bee00000000</code></td>
<td>amount 40 BTC. This is change.</td>
</tr>
<tr>
<td><code>43</code></td>
<td>length of locking script</td>
</tr>
<tr>
<td><code>410411db93e1dcdb</code> <code>8a016b49840f8c53</code> <code>bc1eb68a382e97b1</code> <code>482ecad7b148a690</code> <code>9a5cb2e0eaddfb84</code> <code>ccf9744464f82e16</code> <code>0bfa9b8b64f9d4c0</code> <code>3f999b8643f656b4</code> <code>12a3ac</code></td>
<td>locking script</td>
</tr>
<tr>
<td><code>00000000</code></td>
<td>lock time = unlocked (4 octets)</td>
</tr>
</tbody>
</table>
</div>
<p>I should probably decode the locking scripts on the outputs. <code>41</code> is OP_PUSHDATA for 41<sub>16</sub> bytes. Then we have the 41<sub>16</sub> bytes of data to be pushed onto the stack and finally <code>ac</code> is OP_CHECKSIG which expects a signature and public key on the stack which it takes off the stack and checks. This script only really gets executed when the money is spent.</p>
<p>For historical reasons locking-scripts were called pubkey scripts, unlocking scripts were called signature scripts. But those older names are misleading for newer transaction types.</p>
<p>The <a href="https://bitcoin.stackexchange.com/q/112712/13866">compact form of integers used by Bitcoin</a> is sometimes called varint (variable-length integer) but this is a potential source of confusion as there are other things named varint IIRC.</p>
<p>You can check the little endian numbers by reversing them byte-wise (two hex digits at a time) into a big endian representation and feeding that into Windows Calculator in programmer mode - here's that second output amount (<code>00286bee00000000</code><sub>LE</sub> -&gt; <code>00000000ee6b2800</code><sub>BE</sub>):</p>
<p><a href="https://i.sstatic.net/NVUmQ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/NVUmQ.png" alt="Calculator" /></a></p>
<p>That's how we know <code>00286bee00000000</code> means 40000000000 Satoshi. Which is 40 BTC.</p>
<p>This early transaction is an early type known as Pay to Public Key (P2PK). It is the simplest type. Popular types used nowadays are more complicated.</p>
<p>You can, of course, rather easily get a JSON representation of this transaction using most blockchain explorers.  I find that a bit unsatisfactory as they often introduce some artificial elements (e.g. both 'hex' and 'asm' representations of the script) so you're never certain how exactly the JSON items correspond to parts of the underlying data. Hence the above decoding attempt.</p>
<hr />
<p>Related questions</p>
<ul>
<li><a href="https://bitcoin.stackexchange.com/q/107944/13866">How can I get the destination address from raw transaction data?</a></li>
<li><a href="https://bitcoin.stackexchange.com/q/114108/13866">What are the components of the raw block shown in this image?</a></li>
<li><a href="https://bitcoin.stackexchange.com/q/113697/13866">What are the parts of a Bitcoin transaction in segwit format?</a></li>
</ul>

CC BY-SA 4.0
2022-05-07T13:03:46.713Z
2022-09-27T10:51:07.797Z
2022-09-27T10:51:07.797Z
RedGrittyBrick
<p>Does it store the raw transaction data literally like (excuse the formatting inaccuracies):</p>
<p>0x24134i59435ej3...9 sends 0x9wri03vw3sdfsd...i 26.00000023423 Bitcoin.</p>
<p>Or is it stored differently?</p>

<transactions><block><serialization>
In what format does a block store the transaction data?
Jamo
# In what format does a block store the transaction data?

(Asked by: username_0 on 2022-05-07)

Does it store the raw transaction data literally like (excuse the formatting inaccuracies):

0x24134i59435ej3...9 sends 0x9wri03vw3sdfsd...i 26.00000023423 Bitcoin.

Or is it stored differently?

**Tags:** transactions, block, serialization


---

## 1 answers

### Answer by username_1 on 2022-05-07. Score: 2 | Accepted answer

Bitcoin core stores the data in the network format for [blocks](https://en.bitcoin.it/wiki/Protocol_documentation#block) and for the [transactions](https://en.bitcoin.it/wiki/Protocol_documentation#tx) in those blocks.

---

Here's an example

Block 170 contains the first transaction other than coinbase transactions. In it Satoshi Nakamoto paid Hal Finney 10 BTC. This was the first time one person paid another person in Bitcoin.

Since the data is in binary, we must use a printable representation of it to make it viewable in this web-page. I choose hexadecimal:

```
0100000001c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25
857fcd3704000000004847304402204e45e16932b8af514961a1d3a1a25fdf3f
4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd1290
9d831cc56cbbac4622082221a8768d1d0901ffffffff0200ca9a3b0000000043
4104ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa2
8414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6c
d84cac00286bee0000000043410411db93e1dcdb8a016b49840f8c53bc1eb68a
382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b
64f9d4c03f999b8643f656b412a3ac00000000

```

Some weeks ago I thought it would be neat to work out by hand what that meant. here's how far I got before losing interest:

| Hex Data | Meaning |
| --- | --- |
| `01000000` | Version 1 (little endian uint32) |
| `01` | Number of transaction inputs (compact-int) |
| First input |  |
| `c997a5e56e104102` `fa209c6a852dd906` `60a20b2d9c352423` `edce25857fcd3704` | Hash of referenced transaction (32 octets) |
| `00000000` | index of output in referenced transaction (uint32) |
| `48` | length of unlocking script (compact-int). 48 hex is 72 decimal. |
| `47304402204e45e1` `6932b8af514961a1` `d3a1a25fdf3f4f77` `32e9d624c6c61548` `ab5fb8cd41022018` `1522ec8eca07de48` `60a4acdd12909d83` `1cc56cbbac462208` `2221a8768d1d0901` | unlocking script (72 octets) |
| `ffffffff` | sequence |
| `02` | Number of outputs |
| First output |  |
| `00ca9a3b00000000` | amount 1000000000 satoshi i.e. 10 BTC (int64) |
| `43` | length of locking script |
| `4104ae1a62fe09c5` `f51b13905f07f06b` `99a2f7159b2225f3` `74cd378d71302fa2` `8414e7aab37397f5` `54a7df5f142c21c1` `b7303b8a0626f1ba` `ded5c72a704f7e6c` `d84cac` | locking script |
| Second output |  |
| `00286bee00000000` | amount 40 BTC. This is change. |
| `43` | length of locking script |
| `410411db93e1dcdb` `8a016b49840f8c53` `bc1eb68a382e97b1` `482ecad7b148a690` `9a5cb2e0eaddfb84` `ccf9744464f82e16` `0bfa9b8b64f9d4c0` `3f999b8643f656b4` `12a3ac` | locking script |
| `00000000` | lock time = unlocked (4 octets) |

I should probably decode the locking scripts on the outputs. `41` is OP\_PUSHDATA for 4116 bytes. Then we have the 4116 bytes of data to be pushed onto the stack and finally `ac` is OP\_CHECKSIG which expects a signature and public key on the stack which it takes off the stack and checks. This script only really gets executed when the money is spent.

For historical reasons locking-scripts were called pubkey scripts, unlocking scripts were called signature scripts. But those older names are misleading for newer transaction types.

The [compact form of integers used by Bitcoin](https://bitcoin.stackexchange.com/q/112712/13866) is sometimes called varint (variable-length integer) but this is a potential source of confusion as there are other things named varint IIRC.

You can check the little endian numbers by reversing them byte-wise (two hex digits at a time) into a big endian representation and feeding that into Windows Calculator in programmer mode - here's that second output amount (`00286bee00000000`LE -> `00000000ee6b2800`BE):

[![Calculator](https://i.sstatic.net/NVUmQ.png)](https://i.sstatic.net/NVUmQ.png)

That's how we know `00286bee00000000` means 40000000000 Satoshi. Which is 40 BTC.

This early transaction is an early type known as Pay to Public Key (P2PK). It is the simplest type. Popular types used nowadays are more complicated.

You can, of course, rather easily get a JSON representation of this transaction using most blockchain explorers. I find that a bit unsatisfactory as they often introduce some artificial elements (e.g. both 'hex' and 'asm' representations of the script) so you're never certain how exactly the JSON items correspond to parts of the underlying data. Hence the above decoding attempt.

---

Related questions

* [How can I get the destination address from raw transaction data?](https://bitcoin.stackexchange.com/q/107944/13866)
* [What are the components of the raw block shown in this image?](https://bitcoin.stackexchange.com/q/114108/13866)
* [What are the parts of a Bitcoin transaction in segwit format?](https://bitcoin.stackexchange.com/q/113697/13866)


---

