I've previously been using bitcoin-cli decoderawtransaction to get human readable bitcoin transaction data but am just learning that it's not only decoding the raw transaction but also adding extra derived fields (e.g. txid, hash) that aren't explicitly stated within the transaction held in the blockchain.

Purely as a means of education I want to be able to interact with exactly the transaction data that's stored by bitcoin in blocks/mempool with no extra extrapolated data.

What's the best way to get this data?

1 Answer 1


Why not take that raw hex and decode it yourself? The serialization is documented here: https://en.bitcoin.it/wiki/Protocol_documentation#tx

For example: https://blockstream.info/tx/597d47f1c1653b6e067d8a323c07e0d7702cc92445922e4ba1a61748e0e6fee8

Raw hex:



01000000 version

01 # of inputs

(input 0:)

8a6b50504336d298af1bef59f4292afdbac8ad29a0217ef6d67eb70120f33704 prev out txid

01000000 prev out index

6b length of script (= 107 bytes)

c82c81304a409200095f26ce3f51847c6f11793b3a744818edff7ad3 script

ffffffff nSequence

02 # of outputs

(output 0:)

204e000000000000 value (20,000 satoshis)

19 length of script (=25 bytes)

76a914d2212980d7adf3596d4db7be218d4c0e95944be488ac script

(output 1:)

0980330000000000 value (3,375,113 satoshis)

19 length of script (=25 bytes)

76a91460d6cdf16948d0a40667b7af195f3d233a35b0e288ac script

00000000 locktime

  • thanks - I'm accepting as the answer, but how did you generate that - via a library or with your own code? If it's the latter, any pseudocode you could share for decoding would be very helpful.
    – d3wannabe
    Commented Jul 19, 2019 at 7:09
  • @d3wannabe By hand! With the raw hex and the serialization spec you can sort it all out byte by byte.
    – pinhead
    Commented Jul 19, 2019 at 13:41
  • thanks @pinhead - so "field size" is literally # of characters/bytes? If so, the wiki says version is 4, but you knew to take 8 - how? Also a field like tx_in count (which has a size of 1+) - how do you know it wasn't 018 instead of 01? Think I might be misunderstanding the idea of field size
    – d3wannabe
    Commented Jul 22, 2019 at 4:31
  • @d3wannabe You might be mistaking bytes for hex characters. For example, 01234567 is a hex string that represents 4 bytes.
    – pinhead
    Commented Jul 22, 2019 at 4:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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