<p>Why not take that raw hex and decode it yourself? The serialization is documented here: <a href="https://en.bitcoin.it/wiki/Protocol_documentation#tx" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Protocol_documentation#tx</a></p>

<p>For example: <a href="https://blockstream.info/tx/597d47f1c1653b6e067d8a323c07e0d7702cc92445922e4ba1a61748e0e6fee8" rel="nofollow noreferrer">https://blockstream.info/tx/597d47f1c1653b6e067d8a323c07e0d7702cc92445922e4ba1a61748e0e6fee8</a></p>

<p>Raw hex:</p>

<pre><code>01000000018a6b50504336d298af1bef59f4292afdbac8ad29a0217ef6d67eb70120f33704010
000006b483045022100b0c1bbc3ab2b716f388fe9136cbed2a1e1562fe7a9b8b9847f27284340
85e9e602206351a3b9fb8e04258730856792237e98b9e8d4a89ca10cd5c1dfa68295b9f409012
103ddc5d4f8c82c81304a409200095f26ce3f51847c6f11793b3a744818edff7ad3ffffffff02
204e0000000000001976a914d2212980d7adf3596d4db7be218d4c0e95944be488ac098033000
00000001976a91460d6cdf16948d0a40667b7af195f3d233a35b0e288ac00000000
</code></pre>

<p>Decoded:</p>

<pre><code>01000000 version

01 # of inputs

(input 0:)

8a6b50504336d298af1bef59f4292afdbac8ad29a0217ef6d67eb70120f33704 prev out txid

01000000 prev out index

6b length of script (= 107 bytes)

483045022100b0c1bbc3ab2b716f388fe9136cbed2a1e1562fe7a9b8b9847f2728434085e9e6022
06351a3b9fb8e04258730856792237e98b9e8d4a89ca10cd5c1dfa68295b9f409012103ddc5d4f8
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

</code></pre>

CC BY-SA 4.0
2019-07-19T07:09:46.060Z
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
CC BY-SA 4.0
2019-07-19T13:41:36.113Z
@d3wannabe  By hand! With the raw hex and the serialization spec you can sort it all out byte by byte.
pinhead
CC BY-SA 4.0
2019-07-22T04:31:49.023Z
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
CC BY-SA 4.0
2019-07-22T04:42:35.010Z
@d3wannabe You might be mistaking bytes for hex characters. For example, `01234567` is a hex string that represents 4 bytes.
pinhead
CC BY-SA 4.0
2019-07-19T06:55:17.773Z
2019-09-18T18:36:41.970Z
2019-09-18T18:36:41.970Z
pinhead
<p>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.</p>

<p>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.</p>

<p>What's the best way to get this data? </p>

<transactions><bitcoin-cli>
Viewing truly raw but decoded transaction data
d3wannabe
# Viewing truly raw but decoded transaction data

(Asked by: username_0 on 2019-07-19)

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?

**Tags:** transactions, bitcoin-cli


---

## 1 answers

### Answer by username_1 on 2019-07-19. Score: 2 | Accepted answer

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:

```
01000000018a6b50504336d298af1bef59f4292afdbac8ad29a0217ef6d67eb70120f33704010
000006b483045022100b0c1bbc3ab2b716f388fe9136cbed2a1e1562fe7a9b8b9847f27284340
85e9e602206351a3b9fb8e04258730856792237e98b9e8d4a89ca10cd5c1dfa68295b9f409012
103ddc5d4f8c82c81304a409200095f26ce3f51847c6f11793b3a744818edff7ad3ffffffff02
204e0000000000001976a914d2212980d7adf3596d4db7be218d4c0e95944be488ac098033000
00000001976a91460d6cdf16948d0a40667b7af195f3d233a35b0e288ac00000000

```

Decoded:

```
01000000 version

01 # of inputs

(input 0:)

8a6b50504336d298af1bef59f4292afdbac8ad29a0217ef6d67eb70120f33704 prev out txid

01000000 prev out index

6b length of script (= 107 bytes)

483045022100b0c1bbc3ab2b716f388fe9136cbed2a1e1562fe7a9b8b9847f2728434085e9e6022
06351a3b9fb8e04258730856792237e98b9e8d4a89ca10cd5c1dfa68295b9f409012103ddc5d4f8
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

```

> **Comments:**
> **username_0**: 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.  
> **username_1**: @username_0  By hand! With the raw hex and the serialization spec you can sort it all out byte by byte.  
> **username_0**: thanks @username_1 - 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  
> **username_1**: @username_0 You might be mistaking bytes for hex characters. For example, `01234567` is a hex string that represents 4 bytes.  

---

