<p>You should know that different transaction parsers often include their own fields that aren't directly included in the raw transaction. For example, the "address" would not be found in the raw transaction, but it can be inferred by looking at it. I'm not sure what the 'type' and 'n' fields refer to. You may want to have a look at these links:</p>

<p><a href="https://klmoney.wordpress.com/bitcoin-dissecting-transactions-part-2-building-a-transaction-by-hand/" rel="nofollow noreferrer">dissecting transactions</a></p>

<p><a href="https://medium.com/coinmonks/how-to-create-a-raw-bitcoin-transaction-step-by-step-239b888e87f2" rel="nofollow noreferrer">create raw bitcoin tx</a></p>

<p><a href="https://bitcoin.stackexchange.com/questions/32628/redeeming-a-raw-transaction-step-by-step-example-required">redeeming a raw tx</a></p>

<p>I'm not sure about your questions 1, 3, it'll be specific to the api. I'm not sure what you are referring to in question 2. For question 4, it depends on the type of transaction (non-segwit or segwit) and the type of signature (sighash_all, sighash_none, sighash_single).</p>

CC BY-SA 4.0
2019-12-11T08:35:13.843Z
2019-12-11T08:35:13.843Z
Darius
<p>I have been using this for a long time, and I always skipped the fields. Now that you mention it, here is a partial answer: </p>

<p>1.) I do not know.</p>

<p>2.) The transaction hash appears at the end of the list; it also appears in the link you provided.</p>

<p>3.) Another good question. I do not know.</p>

<p>4.) The fields which are signed come from the previous transaction where, basically, the whole data structure is signed with the exception that the "scriptSig" field is filled with the "pubkey" script.</p>

<p>There are three great sources of documentation on transaction structures:</p>

<p>1.) <a href="https://bitcoin.org/en/developer-guide" rel="nofollow noreferrer">Bitcoin.org Developer Guide</a></p>

<p>2.) <a href="https://rads.stackoverflow.com/amzn/click/1491954388" rel="nofollow noreferrer">"Mastering Bitcoin" by Andreas Antonopoulos</a></p>

<p>3.) <a href="http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html" rel="nofollow noreferrer">Bitcoins the hard way: Using the raw Bitcoin protocol</a></p>

<p>I hope this was beneficial.</p>

CC BY-SA 3.0
2017-12-05T04:21:34.853Z
Thanks for the response. I will look the link that hard way uslng raw bltcoin. The hash that you mentioned in the question 2 is the hash of all transaction. But I am looking for the hash of input transaction hash. It appears in the documention but lt does not exist in the real transaction json.
Orçun Ertuğrul
CC BY-SA 3.0
2017-12-05T19:20:51.843Z
I see. The hash you are looking for does not appear in the tx. This is my answer 3, and indeed is the "tricky" part. An initial transaction is created, with inputs and outputs, and the output script is placed in the sigscript area. This whole structure is then hashed, and signed. Then the output script is removed, and the signature placed in there (and the length fields are adjusted). Quite a bit complicated, when starting, but then with "bitcoins-the-hard-way" fairly easy to understand. Also with Andreas book...
pebwindkraft
CC BY-SA 3.0
2017-12-04T22:09:56.010Z
2017-12-11T17:15:48.830Z
2017-12-11T17:15:48.830Z
pebwindkraft
<p>I guess &quot;spent&quot; tells you if it is an UTXO or not.</p>
<p><a href="https://en.wikipedia.org/wiki/Unspent_transaction_output" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Unspent_transaction_output</a></p>

CC BY-SA 4.0
2021-10-20T16:31:04.747Z
2021-10-20T16:31:04.747Z
cft
<p>I want to understand Bitcoin data structure. So i try to understand a raw transaction in json format. 
When i checked the <a href="https://blockchain.info/api/blockchain_api" rel="noreferrer">blockchain.info API documentation</a>, i see that input structure is defined for transactions like this:</p>

<pre><code>"prev_out":
{
    "hash":"a3e2bcc9a5f776112497a32b05f4b9e5b2405ed9",
    "value":"100000000",
    "tx_index":"12554260",
    "n":"2"
},
"script":"76a914641ad5051edd97029a003fe9efb29359fcee409d88ac"
</code></pre>

<p>But when I <a href="https://blockchain.info/rawtx/ee475443f1fbfff84ffba43ba092a70d291df233bd1428f3d09f7bd1a6054a1f" rel="noreferrer">query a transaction from blockchain.info</a>, it seems differently:</p>

<pre><code>"prev_out":
{
    "spent":true,
    "tx_index":8845778,
    "type":0,
    "addr":"1CfD77hupeUvFwBPxZ2fA8iyWmVwQY22oh",
    "value":10212000000,
    "n":1,
    "script":"76a9147fe34b97aeff4ab754770be5c8f12e2e95332fd488ac"
 }
</code></pre>

<p>Is there any document that clearly explains these data fields? </p>

<p>My current wonders:</p>

<ol>
<li>What is the spent field?</li>
<li>There is no hash field at queried transaction, there must be i think?</li>
<li>What is type field?</li>
<li>Which fields are signed? The signature is generated by which fields hash?</li>
</ol>

CC BY-SA 3.0
2017-12-11T17:21:45.593Z
Hey man, not an exact answer but [here is a video](https://youtu.be/jyDE-aFqJTs?t=292) where a similar transaction layout is described.
DjangoBlockchain
<blockchain.info><api><raw-transaction>
Reading Bitcoin Raw Transaction
Orçun Ertuğrul
# Reading Bitcoin Raw Transaction

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

I want to understand Bitcoin data structure. So i try to understand a raw transaction in json format.
When i checked the [blockchain.info API documentation](https://blockchain.info/api/blockchain_api), i see that input structure is defined for transactions like this:

```
"prev_out":
{
    "hash":"a3e2bcc9a5f776112497a32b05f4b9e5b2405ed9",
    "value":"100000000",
    "tx_index":"12554260",
    "n":"2"
},
"script":"76a914641ad5051edd97029a003fe9efb29359fcee409d88ac"

```

But when I [query a transaction from blockchain.info](https://blockchain.info/rawtx/ee475443f1fbfff84ffba43ba092a70d291df233bd1428f3d09f7bd1a6054a1f), it seems differently:

```
"prev_out":
{
    "spent":true,
    "tx_index":8845778,
    "type":0,
    "addr":"1CfD77hupeUvFwBPxZ2fA8iyWmVwQY22oh",
    "value":10212000000,
    "n":1,
    "script":"76a9147fe34b97aeff4ab754770be5c8f12e2e95332fd488ac"
 }

```

Is there any document that clearly explains these data fields?

My current wonders:

1. What is the spent field?
2. There is no hash field at queried transaction, there must be i think?
3. What is type field?
4. Which fields are signed? The signature is generated by which fields hash?

**Tags:** blockchain.info, api, raw-transaction

> **Comments:**
> **username_1**: Hey man, not an exact answer but [here is a video](https://youtu.be/jyDE-aFqJTs?t=292) where a similar transaction layout is described.  

---

## 3 answers

### Answer by username_2 on 2019-12-11. Score: 1

You should know that different transaction parsers often include their own fields that aren't directly included in the raw transaction. For example, the "address" would not be found in the raw transaction, but it can be inferred by looking at it. I'm not sure what the 'type' and 'n' fields refer to. You may want to have a look at these links:

[dissecting transactions](https://klmoney.wordpress.com/bitcoin-dissecting-transactions-part-2-building-a-transaction-by-hand/)

[create raw bitcoin tx](https://medium.com/coinmonks/how-to-create-a-raw-bitcoin-transaction-step-by-step-239b888e87f2)

[redeeming a raw tx](https://bitcoin.stackexchange.com/questions/32628/redeeming-a-raw-transaction-step-by-step-example-required)

I'm not sure about your questions 1, 3, it'll be specific to the api. I'm not sure what you are referring to in question 2. For question 4, it depends on the type of transaction (non-segwit or segwit) and the type of signature (sighash\_all, sighash\_none, sighash\_single).


---

### Answer by username_3 on 2017-12-04. Score: 0

I have been using this for a long time, and I always skipped the fields. Now that you mention it, here is a partial answer:

1.) I do not know.

2.) The transaction hash appears at the end of the list; it also appears in the link you provided.

3.) Another good question. I do not know.

4.) The fields which are signed come from the previous transaction where, basically, the whole data structure is signed with the exception that the "scriptSig" field is filled with the "pubkey" script.

There are three great sources of documentation on transaction structures:

1.) [Bitcoin.org Developer Guide](https://bitcoin.org/en/developer-guide)

2.) ["Mastering Bitcoin" by Andreas Antonopoulos](https://rads.stackoverflow.com/amzn/click/1491954388)

3.) [Bitcoins the hard way: Using the raw Bitcoin protocol](http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html)

I hope this was beneficial.

> **Comments:**
> **username_0**: Thanks for the response. I will look the link that hard way uslng raw bltcoin. The hash that you mentioned in the question 2 is the hash of all transaction. But I am looking for the hash of input transaction hash. It appears in the documention but lt does not exist in the real transaction json.  
> **username_3**: I see. The hash you are looking for does not appear in the tx. This is my answer 3, and indeed is the "tricky" part. An initial transaction is created, with inputs and outputs, and the output script is placed in the sigscript area. This whole structure is then hashed, and signed. Then the output script is removed, and the signature placed in there (and the length fields are adjusted). Quite a bit complicated, when starting, but then with "bitcoins-the-hard-way" fairly easy to understand. Also with Andreas book...  

---

### Answer by username_4 on 2021-10-20. Score: 0

I guess "spent" tells you if it is an UTXO or not.

<https://en.wikipedia.org/wiki/Unspent_transaction_output>


---

