<p>The format for blocks is described here: <a href="https://bitcoin.org/en/developer-reference#serialized-blocks" rel="nofollow noreferrer">https://bitcoin.org/en/developer-reference#serialized-blocks</a></p>

<p>The format for transactions is mostly described here: <a href="https://bitcoin.org/en/developer-reference#raw-transaction-format" rel="nofollow noreferrer">https://bitcoin.org/en/developer-reference#raw-transaction-format</a></p>

<p>However some transactions are segwit transactions, so they have a few additional fields that are not described in the above documentation. Those fields are described here: <a href="https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki" rel="nofollow noreferrer">https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki</a></p>

<hr>

<p>Your decoding is a bit wrong:</p>

<blockquote>
  <p>00000020 - Transaction Version</p>
</blockquote>

<p>That's the block version, not transaction version.</p>

<blockquote>
  <p>01000000 - Transaction Version</p>
  
  <p>01 - Coinbase has 1 transaction</p>
</blockquote>

<p>You've actually missed two fields here. The first 7 bytes of the transaction are <code>01000000000101</code>. These are as follows:</p>

<pre><code>01000000 - Transaction version
00 - Segwit marker byte
01 - Segwit flag byte
01 - Number of inputs
</code></pre>

<p>Note that the segwit marker and flag bytes are only found in segwit transactions and indicate that a given transaction is a segwit transaction.</p>

<blockquote>
  <p>===== Coinbase Begin =====</p>
</blockquote>

<p>The transaction version and the count after it all belong as part of the coinbase transaction. The count is not of the number of transactions but rather the number of inputs. A transaction is composed of inputs and outputs, not other transactions.</p>

<blockquote>
  <p>-> BE6D6DCAEEFE495F6BCA08E10FF6D24555166C2456D8129213354E32FD73EB1B141AB00100000000000000036507000F312D7B080100275C012F736C7573682F
  - txin</p>
</blockquote>

<p>No, that's still part of the scriptSig. It itself is not a transaction input. This is just arbitrary data in the scriptSig of the coinbase transaction that miners put there.</p>

<blockquote>
  <p>00000000 - Lock Time</p>
  
  <p>===== Coinbase End =====</p>
  
  <p>000000002C6A4C2952534B424C4F434B3AA5BA6C5D1EFFA2034E994BEEE65C619DE2D2A1
  - outpoint ?</p>
  
  <p>B91892F193C170CAB74F152EAE0000000000000000266A24AA21A9ED85F7D06CCF8014D990E0242ACC0433EAF134732094E9A083A45AC3799259C9170000000001000000014FFBE86D2805AF78459BBF5FA3432A5E9C84D408F7921BF2095488B9DDC39D33
  - ?</p>
</blockquote>

<p>No, there are three outputs but you have only decoded one of them.</p>

<p>The proper decoding is as follows:</p>

<pre><code>0000000000000000 - Amount in satoshis
2c - scriptPubKey is 44 bytes
6a - OP_RETURN
4c - OP_PUSHDATA1
29 - Push 41 bytes to stack
52534b424c4f434b3aa5ba6c5d1effa2034e994beee65c619de2d2a1b91892f193c170cab74f152eae - 41 bytes of data
0000000000000000 - Amount in satoshis
26 - scriptPubKey is 38 bytes
6a - OP_RETURN
24 - Push 36 bytes to stack
aa21a9ed85f7d06ccf8014d990e0242acc0433eaf134732094e9a083a45ac3799259c917 - 36 bytes of data. This data is the witness commitment as described in [BIP 141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Commitment_structure)
</code></pre>

<p>There is actually a next part of the transaction that you don't have in your breakdowt. It is the witness data and the locktime.</p>

<p>01 - One witness stack item
20 - Stack item is 32 bytes in length
0000000000000000000000000000000000000000000000000000000000000000 - Stack item
00000000 - locktime</p>

<p>Then the next transaction starts with <code>01000000014FFBE86D2805AF78459BBF5FA3432A5E9C84D408F7921BF2095488B9DDC39D33...</code> and is decoded like the coinbase transaction above.</p>

CC BY-SA 3.0
2018-02-23T16:31:03.877Z
2018-02-23T16:31:03.877Z
Ava Chow
<p>I am attempting to decode a Block and have managed to decode the Coinbase transaction but after the transaction, there is huge gaps in them that I do not understand.</p>

<p>Taking this Block as a sample: <a href="https://blockchain.info/block/0000000000000000002e5b55bf93c89cc3a41de24d762fa4f68e725da3b089ba" rel="nofollow noreferrer">0000000000000000002e5b55bf93c89cc3a41de24d762fa4f68e725da3b089ba</a></p>

<p>Here is my attempt to decode this block:</p>

<blockquote>
  <p>===== Block Begin =====</p>
  
  <p>00000020 - Transaction Version</p>
  
  <p>15F11A82BE84CCCAF4E59CFC0C89EF01CAD854DC15F33D000000000000000000 -
  Block Hash</p>
  
  <p>CC2DCEAF96439181993C564CBE889F60FDB98E8EFD4E524D9EEA3C54CF400504 -
  Merkle Root</p>
  
  <p>2BDF8F5A - Timestamp</p>
  
  <p>DC975D17 - Bits</p>
  
  <p>3E2A4065 - Nonce</p>
  
  <p>FD8704 - Total Transaction</p>
  
  <p>01000000 - Transaction Version </p>
  
  <p>01 - Coinbase has 1 transaction</p>
  
  <p>===== Coinbase Begin =====</p>
  
  <p>0000000000000000000000000000000000000000000000000000000000000000 -
  coinbase hash</p>
  
  <p>FFFFFFFF - index</p>
  
  <p>45 - txin script length (69)</p>
  
  <p>-> 03 - bytes in height</p>
  
  <p>-> 43CA07FA - height</p>
  
  <p>->
  BE6D6DCAEEFE495F6BCA08E10FF6D24555166C2456D8129213354E32FD73EB1B141AB00100000000000000036507000F312D7B080100275C012F736C7573682F
  - txin</p>
  
  <p>00000000 - sequence</p>
  
  <p>03 - 3 output in coinbase</p>
  
  <p>AA5CB94C00000000 - output satoshis from coinbase</p>
  
  <p>19 - Coinbase Output Script Length (25)</p>
  
  <p>76 - OP_DUP</p>
  
  <p>A9 - OP_HASH160</p>
  
  <p>14 - 20 bytes</p>
  
  <p>7C154ED1DC59609E3D26ABB2DF2EA3D587CD8C41 - hash data</p>
  
  <p>88 - OP_EQUALVERIFY</p>
  
  <p>AC - OP_CHECKSIG</p>
  
  <p>00000000 - Lock Time</p>
  
  <p>===== Coinbase End =====</p>
  
  <p>000000002C6A4C2952534B424C4F434B3AA5BA6C5D1EFFA2034E994BEEE65C619DE2D2A1
  - outpoint ?</p>
  
  <p>B91892F193C170CAB74F152EAE0000000000000000266A24AA21A9ED85F7D06CCF8014D990E0242ACC0433EAF134732094E9A083A45AC3799259C9170000000001000000014FFBE86D2805AF78459BBF5FA3432A5E9C84D408F7921BF2095488B9DDC39D33
  - ?</p>
  
  <p>02000000 - Tx Version</p>
  
  <p>6B - TxIn SigScript Length (107)</p>
  
  <p>48 - TxIn SigScript Length (72)</p>
  
  <p>3045022100FAD6F0A91A89A90D17800B55B1B1E424338BFB5D72D3970ED95310AFEB4734A50220120B24AF1444E520EB77ECE73DB6D9775159220B089D28948BC9DBC156C2492F01
  - TxIn SigScript</p>
  
  <p>21 - TxIn SigScript Length (33)</p>
  
  <p>02227CEDFAB55D1B7642D47A5AC92638ED8822A23C3DDADF88DEFEA45A37F5935E -
  TxIn SigScript</p>
  
  <p>FFFFFFFF - TxIn Sequence</p>
  
  <p>02 - TxOut Count</p>
  
  <p>F0874B0000000000 - Satoshis (BTC 0.0495)</p>
  
  <p>17 - Length (23)</p>
  
  <p>A9 - OP_HASH160</p>
  
  <p>14 - 20 bytes</p>
  
  <p>98808E526D3737F044F2DD5445A27DB39BAD821D - hash data</p>
  
  <p>87 - OP_EQUAL</p>
  
  <p>92F6E73600000000 - Satoshis (BTC 9.21171602)</p>
  
  <p>19 - Length (25)</p>
  
  <p>76 - OP_DUP</p>
  
  <p>A9 - OP_HASH160</p>
  
  <p>14 - 20 bytes</p>
  
  <p>B08F46E4D21CD0547A8A1E2E43E5440284F710A4</p>
  
  <p>88 - OP_EQUALVERIFY</p>
  
  <p>AC - OP_CHECKSIG</p>
  
  <p>00000000 - Lock Time</p>
  
  <p>=====================</p>
  
  <p>01000000 - ?</p>
  
  <p>01 - ?</p>
  
  <p>DE74875C17CE6730AF727B52913FAB9FF7922BBA806932785A824A8CAA649E8D0100000000FFFFFFFF02D5C267130000000017A91433A9DB4ED408225EFE4B00DC55F962B52E8769B987A7C6D10200000000220020701A8D401C84FB13E6BAF169D59684E1 ... more data ...</p>
</blockquote>

<p>It seems like after I have decoded the Coinbase transaction, the first proper transaction after the Coinbase, I hit a problem trying to resolve:</p>

<blockquote>
  <p>000000002C6A4C2952534B424C4F434B3AA5BA6C5D1EFFA2034E994BEEE65C619DE2D2A1B91892F193C170CAB74F152EAE0000000000000000266A24AA21A9ED85F7D06CCF8014D990E0242ACC0433EAF134732094E9A083A45AC3799259C9170000000001000000014FFBE86D2805AF78459BBF5FA3432A5E9C84D408F7921BF2095488B9DDC39D33</p>
</blockquote>

<p>Only after that point, does the data look abit more familiar with the 02000000 which I have guessed is the Tx Version followed by what seems to be TxIn Script data and so on.</p>

<p>I would like some help to understand how to decode the Block as this is only that far I can guess after reading the Bitcoin documentations found online which are not documented in a uniformed and easy to ready manner.</p>

<p>Thanks for the help in advance.</p>

CC BY-SA 3.0
2018-02-25T12:40:56.970Z
Use blockchain.info: https://blockchain.info/rawblock/0000000000000000002e5b55bf93c89cc3a41de24d762fa4f68e725da3b089ba
pebwindkraft
<block>
Decoding a Block beyond the Coinbase transaction
thotheolh
# Decoding a Block beyond the Coinbase transaction

(Asked by: username_0 on 2018-02-23)

I am attempting to decode a Block and have managed to decode the Coinbase transaction but after the transaction, there is huge gaps in them that I do not understand.

Taking this Block as a sample: [0000000000000000002e5b55bf93c89cc3a41de24d762fa4f68e725da3b089ba](https://blockchain.info/block/0000000000000000002e5b55bf93c89cc3a41de24d762fa4f68e725da3b089ba)

Here is my attempt to decode this block:

> ===== Block Begin =====
>
> 00000020 - Transaction Version
>
> 15F11A82BE84CCCAF4E59CFC0C89EF01CAD854DC15F33D000000000000000000 -
> Block Hash
>
> CC2DCEAF96439181993C564CBE889F60FDB98E8EFD4E524D9EEA3C54CF400504 -
> Merkle Root
>
> 2BDF8F5A - Timestamp
>
> DC975D17 - Bits
>
> 3E2A4065 - Nonce
>
> FD8704 - Total Transaction
>
> 01000000 - Transaction Version
>
> 01 - Coinbase has 1 transaction
>
> ===== Coinbase Begin =====
>
> 0000000000000000000000000000000000000000000000000000000000000000 -
> coinbase hash
>
> FFFFFFFF - index
>
> 45 - txin script length (69)
>
> -> 03 - bytes in height
>
> -> 43CA07FA - height
>
> ->
> BE6D6DCAEEFE495F6BCA08E10FF6D24555166C2456D8129213354E32FD73EB1B141AB00100000000000000036507000F312D7B080100275C012F736C7573682F
> - txin
>
> 00000000 - sequence
>
> 03 - 3 output in coinbase
>
> AA5CB94C00000000 - output satoshis from coinbase
>
> 19 - Coinbase Output Script Length (25)
>
> 76 - OP\_DUP
>
> A9 - OP\_HASH160
>
> 14 - 20 bytes
>
> 7C154ED1DC59609E3D26ABB2DF2EA3D587CD8C41 - hash data
>
> 88 - OP\_EQUALVERIFY
>
> AC - OP\_CHECKSIG
>
> 00000000 - Lock Time
>
> ===== Coinbase End =====
>
> 000000002C6A4C2952534B424C4F434B3AA5BA6C5D1EFFA2034E994BEEE65C619DE2D2A1
> - outpoint ?
>
> B91892F193C170CAB74F152EAE0000000000000000266A24AA21A9ED85F7D06CCF8014D990E0242ACC0433EAF134732094E9A083A45AC3799259C9170000000001000000014FFBE86D2805AF78459BBF5FA3432A5E9C84D408F7921BF2095488B9DDC39D33
> - ?
>
> 02000000 - Tx Version
>
> 6B - TxIn SigScript Length (107)
>
> 48 - TxIn SigScript Length (72)
>
> 3045022100FAD6F0A91A89A90D17800B55B1B1E424338BFB5D72D3970ED95310AFEB4734A50220120B24AF1444E520EB77ECE73DB6D9775159220B089D28948BC9DBC156C2492F01
> - TxIn SigScript
>
> 21 - TxIn SigScript Length (33)
>
> 02227CEDFAB55D1B7642D47A5AC92638ED8822A23C3DDADF88DEFEA45A37F5935E -
> TxIn SigScript
>
> FFFFFFFF - TxIn Sequence
>
> 02 - TxOut Count
>
> F0874B0000000000 - Satoshis (BTC 0.0495)
>
> 17 - Length (23)
>
> A9 - OP\_HASH160
>
> 14 - 20 bytes
>
> 98808E526D3737F044F2DD5445A27DB39BAD821D - hash data
>
> 87 - OP\_EQUAL
>
> 92F6E73600000000 - Satoshis (BTC 9.21171602)
>
> 19 - Length (25)
>
> 76 - OP\_DUP
>
> A9 - OP\_HASH160
>
> 14 - 20 bytes
>
> B08F46E4D21CD0547A8A1E2E43E5440284F710A4
>
> 88 - OP\_EQUALVERIFY
>
> AC - OP\_CHECKSIG
>
> 00000000 - Lock Time
>
> =====================
>
> 01000000 - ?
>
> 01 - ?
>
> DE74875C17CE6730AF727B52913FAB9FF7922BBA806932785A824A8CAA649E8D0100000000FFFFFFFF02D5C267130000000017A91433A9DB4ED408225EFE4B00DC55F962B52E8769B987A7C6D10200000000220020701A8D401C84FB13E6BAF169D59684E1 ... more data ...

It seems like after I have decoded the Coinbase transaction, the first proper transaction after the Coinbase, I hit a problem trying to resolve:

> 000000002C6A4C2952534B424C4F434B3AA5BA6C5D1EFFA2034E994BEEE65C619DE2D2A1B91892F193C170CAB74F152EAE0000000000000000266A24AA21A9ED85F7D06CCF8014D990E0242ACC0433EAF134732094E9A083A45AC3799259C9170000000001000000014FFBE86D2805AF78459BBF5FA3432A5E9C84D408F7921BF2095488B9DDC39D33

Only after that point, does the data look abit more familiar with the 02000000 which I have guessed is the Tx Version followed by what seems to be TxIn Script data and so on.

I would like some help to understand how to decode the Block as this is only that far I can guess after reading the Bitcoin documentations found online which are not documented in a uniformed and easy to ready manner.

Thanks for the help in advance.

**Tags:** block

> **Comments:**
> **username_1**: Use blockchain.info: https://blockchain.info/rawblock/0000000000000000002e5b55bf93c89cc3a41de24d762fa4f68e725da3b089ba  

---

## 1 answers

### Answer by username_2 on 2018-02-23. Score: 1 | Accepted answer

The format for blocks is described here: <https://bitcoin.org/en/developer-reference#serialized-blocks>

The format for transactions is mostly described here: <https://bitcoin.org/en/developer-reference#raw-transaction-format>

However some transactions are segwit transactions, so they have a few additional fields that are not described in the above documentation. Those fields are described here: <https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki>

---

Your decoding is a bit wrong:

> 00000020 - Transaction Version

That's the block version, not transaction version.

> 01000000 - Transaction Version
>
> 01 - Coinbase has 1 transaction

You've actually missed two fields here. The first 7 bytes of the transaction are `01000000000101`. These are as follows:

```
01000000 - Transaction version
00 - Segwit marker byte
01 - Segwit flag byte
01 - Number of inputs

```

Note that the segwit marker and flag bytes are only found in segwit transactions and indicate that a given transaction is a segwit transaction.

> ===== Coinbase Begin =====

The transaction version and the count after it all belong as part of the coinbase transaction. The count is not of the number of transactions but rather the number of inputs. A transaction is composed of inputs and outputs, not other transactions.

> -> BE6D6DCAEEFE495F6BCA08E10FF6D24555166C2456D8129213354E32FD73EB1B141AB00100000000000000036507000F312D7B080100275C012F736C7573682F
> - txin

No, that's still part of the scriptSig. It itself is not a transaction input. This is just arbitrary data in the scriptSig of the coinbase transaction that miners put there.

> 00000000 - Lock Time
>
> ===== Coinbase End =====
>
> 000000002C6A4C2952534B424C4F434B3AA5BA6C5D1EFFA2034E994BEEE65C619DE2D2A1
> - outpoint ?
>
> B91892F193C170CAB74F152EAE0000000000000000266A24AA21A9ED85F7D06CCF8014D990E0242ACC0433EAF134732094E9A083A45AC3799259C9170000000001000000014FFBE86D2805AF78459BBF5FA3432A5E9C84D408F7921BF2095488B9DDC39D33
> - ?

No, there are three outputs but you have only decoded one of them.

The proper decoding is as follows:

```
0000000000000000 - Amount in satoshis
2c - scriptPubKey is 44 bytes
6a - OP_RETURN
4c - OP_PUSHDATA1
29 - Push 41 bytes to stack
52534b424c4f434b3aa5ba6c5d1effa2034e994beee65c619de2d2a1b91892f193c170cab74f152eae - 41 bytes of data
0000000000000000 - Amount in satoshis
26 - scriptPubKey is 38 bytes
6a - OP_RETURN
24 - Push 36 bytes to stack
aa21a9ed85f7d06ccf8014d990e0242acc0433eaf134732094e9a083a45ac3799259c917 - 36 bytes of data. This data is the witness commitment as described in [BIP 141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Commitment_structure)

```

There is actually a next part of the transaction that you don't have in your breakdowt. It is the witness data and the locktime.

01 - One witness stack item
20 - Stack item is 32 bytes in length
0000000000000000000000000000000000000000000000000000000000000000 - Stack item
00000000 - locktime

Then the next transaction starts with `01000000014FFBE86D2805AF78459BBF5FA3432A5E9C84D408F7921BF2095488B9DDC39D33...` and is decoded like the coinbase transaction above.


---

