2

I'm trying to figure out how to derive the addresses field from a serialized tx. Take for instance this transaction on the test network

46993a02c0f271e8106159581fd2329d46818b9888b5123290c5d1da1718b8b9

The serialized format for this tx is

0100000002b90e7eb0e0cb1c9127bb5c48f78c753462e26128b4a1f7fd60777a039751d87101000000fdfe0000483045022100c2602e5f6bb2a0df006f734493a404f491abade27f2c1a9d0c7c7fd249de00b20220111b273b653dc2d0ec890e10d89d7e7a095fd88e27e588f5a60ba5d80ad3c8bb01483045022100cc574b83104238d94e8c6abda28d33ce2377c324263bfa62ce6f240fa60356fb0220117970c87c00169630f5f368bf90f0f11ea156a7befdab0299ee4f3577a229ed014c695221031d1f0c5147b30190cc837b180c2e2a09733f4fd5d146809091950a80383e92682103bb7f1955df8f9b52bfaa908a0e968ad019ef5e8b832ae405e6d882aeda10ec5321028ea4acd57ae1abd53260b32d252472691ea4402d9ac9d4d0fb8fb4636544a4d453aeffffffffb90e7eb0e0cb1c9127bb5c48f78c753462e26128b4a1f7fd60777a039751d87100000000fdfd0000483045022100b922b6495ce11ab5b8959e0fb97a40bc98011d32b81ece252f2d3bfaf3c34ccf0220194951276272a21c7c0e001d26e68ca9a532927c0c703902ac96a4933824b0e101473044022100dd7bbfba7d765843580d158bf9ef92ba34798d82a42e0098b8acd229cfd6afc3021f55d516e1913bbce390e6fd251d4da483a05e7cb8e510a02f9c6e2d92e574da014c69522103e9b16e8ef73855ffa479d7c1b655f99d6834003c6608210b575a0c6bc6c062632103f12e2f8a3357ba47e8ea91b5ce2325dbc9346e4d2bf8db5d30f9422201bc320e210392a98eb30cb3840e47b3b081f43508da37e499272ede8c95f27b9afca813257953aeffffffff0280a903000000000017a9145868dadcf00a6fff4cc54752e6e75b046d24aad6878ab1a8000000000017a914d81e64eb5a16486b3b5b9dc14eda3412e40ca8638700000000

the json format is this:

{
    "hex" : "0100000002b90e7eb0e0cb1c9127bb5c48f78c753462e26128b4a1f7fd60777a039751d87101000000fdfe0000483045022100c2602e5f6bb2a0df006f734493a404f491abade27f2c1a9d0c7c7fd249de00b20220111b273b653dc2d0ec890e10d89d7e7a095fd88e27e588f5a60ba5d80ad3c8bb01483045022100cc574b83104238d94e8c6abda28d33ce2377c324263bfa62ce6f240fa60356fb0220117970c87c00169630f5f368bf90f0f11ea156a7befdab0299ee4f3577a229ed014c695221031d1f0c5147b30190cc837b180c2e2a09733f4fd5d146809091950a80383e92682103bb7f1955df8f9b52bfaa908a0e968ad019ef5e8b832ae405e6d882aeda10ec5321028ea4acd57ae1abd53260b32d252472691ea4402d9ac9d4d0fb8fb4636544a4d453aeffffffffb90e7eb0e0cb1c9127bb5c48f78c753462e26128b4a1f7fd60777a039751d87100000000fdfd0000483045022100b922b6495ce11ab5b8959e0fb97a40bc98011d32b81ece252f2d3bfaf3c34ccf0220194951276272a21c7c0e001d26e68ca9a532927c0c703902ac96a4933824b0e101473044022100dd7bbfba7d765843580d158bf9ef92ba34798d82a42e0098b8acd229cfd6afc3021f55d516e1913bbce390e6fd251d4da483a05e7cb8e510a02f9c6e2d92e574da014c69522103e9b16e8ef73855ffa479d7c1b655f99d6834003c6608210b575a0c6bc6c062632103f12e2f8a3357ba47e8ea91b5ce2325dbc9346e4d2bf8db5d30f9422201bc320e210392a98eb30cb3840e47b3b081f43508da37e499272ede8c95f27b9afca813257953aeffffffff0280a903000000000017a9145868dadcf00a6fff4cc54752e6e75b046d24aad6878ab1a8000000000017a914d81e64eb5a16486b3b5b9dc14eda3412e40ca8638700000000",
    "txid" : "46993a02c0f271e8106159581fd2329d46818b9888b5123290c5d1da1718b8b9",
    "version" : 1,
    "locktime" : 0,
    "vin" : [
        {
            "txid" : "71d85197037a7760fdf7a1b42861e26234758cf7485cbb27911ccbe0b07e0eb9",
            "vout" : 1,
            "scriptSig" : {
                "asm" : "0 3045022100c2602e5f6bb2a0df006f734493a404f491abade27f2c1a9d0c7c7fd249de00b20220111b273b653dc2d0ec890e10d89d7e7a095fd88e27e588f5a60ba5d80ad3c8bb01 3045022100cc574b83104238d94e8c6abda28d33ce2377c324263bfa62ce6f240fa60356fb0220117970c87c00169630f5f368bf90f0f11ea156a7befdab0299ee4f3577a229ed01 5221031d1f0c5147b30190cc837b180c2e2a09733f4fd5d146809091950a80383e92682103bb7f1955df8f9b52bfaa908a0e968ad019ef5e8b832ae405e6d882aeda10ec5321028ea4acd57ae1abd53260b32d252472691ea4402d9ac9d4d0fb8fb4636544a4d453ae",
                "hex" : "00483045022100c2602e5f6bb2a0df006f734493a404f491abade27f2c1a9d0c7c7fd249de00b20220111b273b653dc2d0ec890e10d89d7e7a095fd88e27e588f5a60ba5d80ad3c8bb01483045022100cc574b83104238d94e8c6abda28d33ce2377c324263bfa62ce6f240fa60356fb0220117970c87c00169630f5f368bf90f0f11ea156a7befdab0299ee4f3577a229ed014c695221031d1f0c5147b30190cc837b180c2e2a09733f4fd5d146809091950a80383e92682103bb7f1955df8f9b52bfaa908a0e968ad019ef5e8b832ae405e6d882aeda10ec5321028ea4acd57ae1abd53260b32d252472691ea4402d9ac9d4d0fb8fb4636544a4d453ae"
            },
            "sequence" : 4294967295
        },
        {
            "txid" : "71d85197037a7760fdf7a1b42861e26234758cf7485cbb27911ccbe0b07e0eb9",
            "vout" : 0,
            "scriptSig" : {
                "asm" : "0 3045022100b922b6495ce11ab5b8959e0fb97a40bc98011d32b81ece252f2d3bfaf3c34ccf0220194951276272a21c7c0e001d26e68ca9a532927c0c703902ac96a4933824b0e101 3044022100dd7bbfba7d765843580d158bf9ef92ba34798d82a42e0098b8acd229cfd6afc3021f55d516e1913bbce390e6fd251d4da483a05e7cb8e510a02f9c6e2d92e574da01 522103e9b16e8ef73855ffa479d7c1b655f99d6834003c6608210b575a0c6bc6c062632103f12e2f8a3357ba47e8ea91b5ce2325dbc9346e4d2bf8db5d30f9422201bc320e210392a98eb30cb3840e47b3b081f43508da37e499272ede8c95f27b9afca813257953ae",
                "hex" : "00483045022100b922b6495ce11ab5b8959e0fb97a40bc98011d32b81ece252f2d3bfaf3c34ccf0220194951276272a21c7c0e001d26e68ca9a532927c0c703902ac96a4933824b0e101473044022100dd7bbfba7d765843580d158bf9ef92ba34798d82a42e0098b8acd229cfd6afc3021f55d516e1913bbce390e6fd251d4da483a05e7cb8e510a02f9c6e2d92e574da014c69522103e9b16e8ef73855ffa479d7c1b655f99d6834003c6608210b575a0c6bc6c062632103f12e2f8a3357ba47e8ea91b5ce2325dbc9346e4d2bf8db5d30f9422201bc320e210392a98eb30cb3840e47b3b081f43508da37e499272ede8c95f27b9afca813257953ae"
            },
            "sequence" : 4294967295
        }
    ],
    "vout" : [
        {
            "value" : 0.00240000,
            "n" : 0,
            "scriptPubKey" : {
                "asm" : "OP_HASH160 5868dadcf00a6fff4cc54752e6e75b046d24aad6 OP_EQUAL",
                "hex" : "a9145868dadcf00a6fff4cc54752e6e75b046d24aad687",
                "reqSigs" : 1,
                "type" : "scripthash",
                "addresses" : [
                    "2N1Jh4cYEFPvw43kZaJovks3hwMWFRUdJ9E"
                ]
            }
        },
        {
            "value" : 0.11055498,
            "n" : 1,
            "scriptPubKey" : {
                "asm" : "OP_HASH160 d81e64eb5a16486b3b5b9dc14eda3412e40ca863 OP_EQUAL",
                "hex" : "a914d81e64eb5a16486b3b5b9dc14eda3412e40ca86387",
                "reqSigs" : 1,
                "type" : "scripthash",
                "addresses" : [
                    "2NCwxMYedhG73QXxDC8jDXY9i5mw4KGcAqo"
                ]
            }
        }
    ],
    "blockhash" : "0000000000000fc2902d17140996a27be5d9dfaf8480ea786fa83dc656da72ca",
    "confirmations" : 10,
    "time" : 1452693415,
    "blocktime" : 1452693415
}

I'm looking through the developer guide examples, and it does not seem like the addresses field on the vout's are actually serialized. The same thing is true for reqSigs. How are they being derived for the transaction if they are not explicitly serialized inside of it?

1

The fields you are looking for, addresses and reqSigs, are indeed serialized in the transaction. In particular, they are implied by the scriptPubKey binary string.

The scriptPubKey field is very general, supporting many payment types and even arbitrary garbage data (unfortunately).

The format for pay-to-pubkey-hash (P2PKH) is <OP_DUP> <OP_HASH160> <push 20-byte pubKeyHash> <OP_EQUALVERIFY> <OP_CHECKSIG> [source]. The 20-byte hash is converted via Base58Check into the address string. And as per the documentation you linked to, reqSigs is 1 for P2PKH.

Another format for the script is a bare multisig, and this will allow reqSigs to be greater than 1.

Note that the JSON data is produced by a function named DecodeRawTransaction. This is why the output data seems to be different from the input data, because additional processing and interpretation was performed on it.

|improve this answer|||||

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.