<p>I found it:</p>

<p>Each witness field starts with a compactSize integer to indicate the number of stack items for the corresponding txin. It is then followed by witness stack item(s) for the corresponding txin, if any. </p>

<p>Each witness stack item starts with a compactSize integer to indicate the number of bytes of the item.   </p>

<p>If a txin is not associated with any witness data, its corresponding witness field is an exact 0x00, indicating that the number of witness stack items is zero.</p>

<pre><code>for each input {
    stackItems = read integer
    if stackItems &gt; 0 {
        for each stackItem {
            bytes = read integer
            //witness data is bytes long
        }
    }
}
</code></pre>

CC BY-SA 3.0
2017-12-20T13:02:35.270Z
Do you know the databytes regarding "stackItems" and "bytes"?
Erhard Dinhobl
CC BY-SA 3.0
2017-12-20T13:13:09.967Z
The stackItems must NOT be read. It is the txInCount! And the "bytes" is CompactSize Unsigned Integer value. fyi - see https://bitcoincore.org/en/segwit_wallet_dev/
Erhard Dinhobl
CC BY-SA 3.0
2017-07-04T20:34:53.490Z
2017-07-04T20:34:53.490Z
Albert S
<p>I'm parsing s SegWit transaction, I got it done until i reach the witness data.<br>
How big is the witness data?</p>

<raw-transaction><segregated-witness>
Parsing a SegWit transaction - what is the size of witness data?
Albert S
# Parsing a SegWit transaction - what is the size of witness data?

(Asked by: username_0 on 2017-07-04)

I'm parsing s SegWit transaction, I got it done until i reach the witness data.  
How big is the witness data?

**Tags:** raw-transaction, segregated-witness


---

## 1 answers

### Answer by username_0 on 2017-07-04. Score: 4

I found it:

Each witness field starts with a compactSize integer to indicate the number of stack items for the corresponding txin. It is then followed by witness stack item(s) for the corresponding txin, if any.

Each witness stack item starts with a compactSize integer to indicate the number of bytes of the item.

If a txin is not associated with any witness data, its corresponding witness field is an exact 0x00, indicating that the number of witness stack items is zero.

```
for each input {
    stackItems = read integer
    if stackItems > 0 {
        for each stackItem {
            bytes = read integer
            //witness data is bytes long
        }
    }
}

```

> **Comments:**
> **username_1**: Do you know the databytes regarding "stackItems" and "bytes"?  
> **username_1**: The stackItems must NOT be read. It is the txInCount! And the "bytes" is CompactSize Unsigned Integer value. fyi - see https://bitcoincore.org/en/segwit_wallet_dev/  

---

