createrawtransaction(...) in testnet returns this hex:


I know how to decode this with decoderawtransaction but if I want to do this programmatically how can I do it? In other words, what is the exact encoding/format of this hex and how can I decode it into plain text or json using c# or some other language?

The decoded text should be:

    "addresses": [
    "block_height": -1, 
    "block_index": -1, 
    "confidence": 0, 
    "confirmations": 0, 
    "double_spend": false, 
    "fees": 500000, 
    "hash": "b020bdec4e92cb69db93557dcbbfcc73076fc01f6828e41eb3ef5f628414ee62", 
    "inputs": [
            "addresses": [
            "age": 2596, 
            "output_index": 0, 
            "output_value": 514729939, 
            "prev_hash": "7bff92f5853eb1c06112f8c532ddda687e95bfe55ad7982f88f0c09d13c37004", 
            "script": "", 
            "script_type": "pay-to-pubkey-hash", 
            "sequence": 4294967295
    "lock_time": 0, 
    "outputs": [
            "addresses": [
            "script": "76a9140f39a0043cf7bdbe429c17e8b514599e9ec53dea88ac", 
            "script_type": "pay-to-pubkey-hash", 
            "value": 514229938
            "addresses": [
            "script": "76a9148a8c9fd79173f90cf76410615d2a52d12d27d21288ac", 
            "script_type": "pay-to-pubkey-hash", 
            "value": 1
    "preference": "high", 
    "received": "2016-01-22T12:58:23.224606219Z", 
    "relayed_by": ",", 
    "size": 119, 
    "total": 514229939, 
    "ver": 1, 
    "vin_sz": 1, 
    "vout_sz": 2

Reference: decoderawtransaction in C++

1 Answer 1


This is specified thoroughly on the Bitcoin Wiki.

The first 4 bytes are the version number, the next 1-9 bytes are the number of inputs (almost never more than 1 byte) and so on.

Programitically, there are a ton of libraries that take the raw text and spit out the json as the bitcoin RPC call does in your example. They all use the same specification, though, so you can create the code yourself or use something already written.

  • it would be cool if you point to the method on these libs which does the conversion
    – Sunny
    Commented Sep 20, 2018 at 13:14
  • Hi, I'm using bitcoinj and I want create raw transaction without creating wallet instance in android. Can you please help me how can I do that?
    – Kush
    Commented Dec 31, 2018 at 12:50

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.