3

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, 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, 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?
0

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

create raw bitcoin tx

redeeming a raw tx

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).

-1

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

2.) "Mastering Bitcoin" by Andreas Antonopoulos

3.) Bitcoins the hard way: Using the raw Bitcoin protocol

I hope this was beneficial.

  • 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 Dec 5 '17 at 4:21
  • 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 Dec 5 '17 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.