<p>This is a <a href="https://bitcoincore.org/en/segwit_wallet_dev/#transaction-serialization" rel="nofollow noreferrer">SegWit transaction</a>, serialized using the new format defined in <a href="https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki" rel="nofollow noreferrer">BIP144</a>.</p>

<p>The format is only permitted when at least one of the transaction inputs has a witness, and works as follows:</p>

<ul>
<li>4-byte integer nVersion</li>
<li>1-byte dummy (must be 0)</li>
<li>1-byte flags (must be nonzero)</li>
<li>vector(transaction inputs)</li>
<li>vector(transaction outputs)</li>
<li>if (flags &amp; 1): vector(input witnesses) (excluding the length, which is implied by the number of transaction inputs)</li>
<li>4-byte integer nLockTime</li>
</ul>

<p>The dummy byte is required to be 0, guaranteeing that the transaction cannot be misinterpreted by old software (as by consensus rules, a transaction with 0 inputs is invalid).</p>

CC BY-SA 4.0
2017-12-13T06:05:19.013Z
2018-07-26T10:59:41.860Z
2018-07-26T10:59:41.860Z
Pieter Wuille
<p>These are two raw transactions I got from Testnet, using <code>bitcoind -testnet</code>.</p>

<p><code>01000000000101dc82cf0b892b325413ec7b3237e1a122c3114002ccd6e0f0157c8851144c00200100000017160014a530e459b62406b99aa75091bd9eb833a20698a3ffffffff0290f4f700000000001976a9143eabc5342434987e43e5c49f42462689d969c56288ac67baa26f2e00000017a9144d62bfc7376858c8d601c50dc08d8dc8491b27a8870247304402206998883f24133677c46a70e01e70cd9f69ee9059a4d5d82e891b82e797f125000220760a3af0836a9068de63ca0a4cedbb68bc8ea2d067f5cdaf92f2cd4d31703e18012103d8421b44b3d21151a5a2660662bc6ef69a0ef2266bf68b8c56eea715b23a596500000000</code></p>

<p><code>0100000000010151df0e2bb6bd3ffa19ae03330b7f89a4a8d6ad93bc204ec7d8cd367e58a10b580100000017160014a03506f19e6851264f21f373bae14023d247d760ffffffff02bc733400000000001976a9143d19e810138ebcb0033c462cf2b5e62a9d7af24588acc4ecca632e00000017a9142f877141344c0202e2f6eb979025d9e3f4f38c6a87024730440220342f74d49243d342a8cd3818e48d8aaf94c71fa41a96863dd986057992650bc202202a7cbe1541941e55abf06fee496c890cce9a2d2fcbb0710fb24342f3b513cd0a0121029e3868ce4a192e0b47f29090c243764e68b4c2c18aa0476272a61b62e3a3804c00000000</code></p>

<p>When I try to parse these transactions using <code>new bitcore.Transaction(serialized)</code> via Bitcore library, the return value either results in Buffer error or malformed Transaction.</p>

<p>When I refer the <a href="https://en.bitcoin.it/w/images/en/e/e1/TxBinaryMap.png" rel="nofollow noreferrer">Bitcoin doc</a>, the first 4 bytes are assigned to be <strong>version</strong>, and the following bytes are assigned to be <strong>the number of inputs</strong>, in the <a href="https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer" rel="nofollow noreferrer">variable length integer format</a>. Variable length integer has the value of <code>uint8_t</code> when its value is less than 0xFD, according to the doc.</p>

<p>Following the rule, above two raw transactions should indicate that these transactions have <strong>zero input</strong> because it has <code>01000000</code>, thus <strong>1</strong> in little endian (so it means version 1), which is followed by <code>00</code>, thus <strong>0</strong> (so it means 0 input) according to the doc.</p>

<p>But when I decode these raw transactions either at <a href="https://live.blockcypher.com/btc-testnet/decodetx/" rel="nofollow noreferrer">BlockCypher</a> or by <code>bitcoin-cli decoderawtransaction</code>, it clearly shows that it has some input and the result seems to be valid. (By querying the tx id or addresses, I can get a valid result too.)</p>

<p>Is there any other way to decode these kind of raw transactions?</p>

<bitcoin-core><raw-transaction><bitcore>
How to decode raw transaction which has 00 in '#TxIn' slot?
Lee Han Kyeol
# How to decode raw transaction which has 00 in '#TxIn' slot?

(Asked by: username_0 on 2017-12-13)

These are two raw transactions I got from Testnet, using `bitcoind -testnet`.

`01000000000101dc82cf0b892b325413ec7b3237e1a122c3114002ccd6e0f0157c8851144c00200100000017160014a530e459b62406b99aa75091bd9eb833a20698a3ffffffff0290f4f700000000001976a9143eabc5342434987e43e5c49f42462689d969c56288ac67baa26f2e00000017a9144d62bfc7376858c8d601c50dc08d8dc8491b27a8870247304402206998883f24133677c46a70e01e70cd9f69ee9059a4d5d82e891b82e797f125000220760a3af0836a9068de63ca0a4cedbb68bc8ea2d067f5cdaf92f2cd4d31703e18012103d8421b44b3d21151a5a2660662bc6ef69a0ef2266bf68b8c56eea715b23a596500000000`

`0100000000010151df0e2bb6bd3ffa19ae03330b7f89a4a8d6ad93bc204ec7d8cd367e58a10b580100000017160014a03506f19e6851264f21f373bae14023d247d760ffffffff02bc733400000000001976a9143d19e810138ebcb0033c462cf2b5e62a9d7af24588acc4ecca632e00000017a9142f877141344c0202e2f6eb979025d9e3f4f38c6a87024730440220342f74d49243d342a8cd3818e48d8aaf94c71fa41a96863dd986057992650bc202202a7cbe1541941e55abf06fee496c890cce9a2d2fcbb0710fb24342f3b513cd0a0121029e3868ce4a192e0b47f29090c243764e68b4c2c18aa0476272a61b62e3a3804c00000000`

When I try to parse these transactions using `new bitcore.Transaction(serialized)` via Bitcore library, the return value either results in Buffer error or malformed Transaction.

When I refer the [Bitcoin doc](https://en.bitcoin.it/w/images/en/e/e1/TxBinaryMap.png), the first 4 bytes are assigned to be **version**, and the following bytes are assigned to be **the number of inputs**, in the [variable length integer format](https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer). Variable length integer has the value of `uint8_t` when its value is less than 0xFD, according to the doc.

Following the rule, above two raw transactions should indicate that these transactions have **zero input** because it has `01000000`, thus **1** in little endian (so it means version 1), which is followed by `00`, thus **0** (so it means 0 input) according to the doc.

But when I decode these raw transactions either at [BlockCypher](https://live.blockcypher.com/btc-testnet/decodetx/) or by `bitcoin-cli decoderawtransaction`, it clearly shows that it has some input and the result seems to be valid. (By querying the tx id or addresses, I can get a valid result too.)

Is there any other way to decode these kind of raw transactions?

**Tags:** bitcoin-core, raw-transaction, bitcore


---

## 1 answers

### Answer by username_1 on 2017-12-13. Score: 5 | Accepted answer

This is a [SegWit transaction](https://bitcoincore.org/en/segwit_wallet_dev/#transaction-serialization), serialized using the new format defined in [BIP144](https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki).

The format is only permitted when at least one of the transaction inputs has a witness, and works as follows:

* 4-byte integer nVersion
* 1-byte dummy (must be 0)
* 1-byte flags (must be nonzero)
* vector(transaction inputs)
* vector(transaction outputs)
* if (flags & 1): vector(input witnesses) (excluding the length, which is implied by the number of transaction inputs)
* 4-byte integer nLockTime

The dummy byte is required to be 0, guaranteeing that the transaction cannot be misinterpreted by old software (as by consensus rules, a transaction with 0 inputs is invalid).


---

