<p>The <strong><a href="https://github.com/libbitcoin/libbitcoin-explorer/wiki" rel="nofollow noreferrer">bitcoin-exlporer (bx) tool</a></strong> applied below does not yet support the segwit-encoded portion of analyzing a raw hexadecimal transaction (TX).  However, the bx commands below can analyze the results offline given the supplied raw TX provided above, and two pertinent TXs associated with the two input UTXOs.</p>

<p><strong>% echo 01000000000102b4370d52c1e1dc67b0250ef7bd5265146d4def0beacfefd99660a86baf97faf000000000232200202dc520822e73d4262000d3b456b16df1d07b0ba9d238f3063379d65840fd38e7feffffff92e7b08c7a67a7a783b52d83e7b051a4812e496fac181aaadcaa69a3b526ca500100000023220020357bc74e1f825c4628519a3322f2aa9b2c5bd55b523149d4e1f7fe2f273ce7d6feffffff02a08601000000000017a914113e1767186f0280174123ad0c22e8929f994c1c87f4fd01000000000017a9148160a47aeafb68288f0df8551d5d9dddd22a643387040047304402202575f8326e510b8213d70a8213ab1a36cd2984b16673ef3579960d0089ad13de022020ec4e78129c084103909acec0319f7d326fff699de142ab354be9570d68dc170147304402202bc22860e84e0311bbc175940c2b3b5435255dc7ca3fb0d12e5f03df80237b880220536eceee1aace094825f0fd884d057e395102f4e4627188fe6dd5648cdc7a457014752210274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8210343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d46352ae0400473044022042d6861f81b617cfbe51e7efefb59dd990d4c0057b43645d2f006db93b38c59e02204595b7f822546082b0ee1efb6966c97b2d8174c96b670a10bc9d78d3cf7ba99101483045022100bb3a612fe17f261a0c5e9db20a087362c10556571ef54866ab29cfdb94975236022037bebec4c0459bba21656cb36b331313c2dd6008ed7a2479efca659c7fc97c9d0147522103838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b4722103c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d52ae2f3f0800 | bx tx-decode</strong></p>



<pre><code>{
    hash b0dd3d915a568c9d48e37b3fbfca58ae3276a5dba176fdf30f18af794310cc02
    inputs
    {
        input
        {
            address_hash 49e282ad0605c1cb63ff45fc34b14357859e8d08
            previous_output
            {
                hash f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4
                index 0
            }
            script [00202dc520822e73d4262000d3b456b16df1d07b0ba9d238f3063379d65840fd38e7]
            sequence 4294967294
            witness "[] [304402202575f8326e510b8213d70a8213ab1a36cd2984b16673ef3579960d0089ad13de022020ec4e78129c084103909acec0319f7d326fff699de142ab354be9570d68dc1701] [304402202bc22860e84e0311bbc175940c2b3b5435255dc7ca3fb0d12e5f03df80237b880220536eceee1aace094825f0fd884d057e395102f4e4627188fe6dd5648cdc7a45701] [52210274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8210343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d46352ae]"
        }
        input
        {
            address_hash 70871ecb261f3df9a9d325b33ef6d8acb5074258
            previous_output
            {
                hash 50ca26b5a369aadcaa1a18ac6f492e81a451b0e7832db583a7a7677a8cb0e792
                index 1
            }
            script [0020357bc74e1f825c4628519a3322f2aa9b2c5bd55b523149d4e1f7fe2f273ce7d6]
            sequence 4294967294
            witness "[] [3044022042d6861f81b617cfbe51e7efefb59dd990d4c0057b43645d2f006db93b38c59e02204595b7f822546082b0ee1efb6966c97b2d8174c96b670a10bc9d78d3cf7ba99101] [3045022100bb3a612fe17f261a0c5e9db20a087362c10556571ef54866ab29cfdb94975236022037bebec4c0459bba21656cb36b331313c2dd6008ed7a2479efca659c7fc97c9d01] [522103838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b4722103c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d52ae]"
        }
    }
    lock_time 540463
    outputs
    {
        output
        {
            address_hash 113e1767186f0280174123ad0c22e8929f994c1c
            script "hash160 [113e1767186f0280174123ad0c22e8929f994c1c] equal"
            value 100000
        }
        output
        {
            address_hash 8160a47aeafb68288f0df8551d5d9dddd22a6433
            script "hash160 [8160a47aeafb68288f0df8551d5d9dddd22a6433] equal"
            value 130548
        }
    }
    version 1
}
</code></pre>

<p>Then one needs to examine the encumbrance scripts associated with the following to affirm determine if they P2PKH or P2SH address types:</p>

<p>1) transaction ID f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4 and index 0</p>

<p>2) transaction ID 50ca26b5a369aadcaa1a18ac6f492e81a451b0e7832db583a7a7677a8cb0e792 and index 1</p>

<p><strong>% bx fetch-tx -c ~/bitcoin-explorer/bx-mainnet-remote.cfg f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4</strong></p>

<pre><code>transaction
{
    hash f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4
    inputs
    {
        input
        {
            address_hash 40ef0e3af404842b44912f6a65ca4adfb8f93a1a
            previous_output
            {
                hash f0eda490f5e8c3096b74b66524ff9c7b6fa1b9d4280e8372476af1d202a8b360
                index 1
            }
            script [0020de730ce4f827ac7c63ea8c9a47419875eacaf167f9391eb5d30817a181aca8d3]
            sequence 4294967294
        }
    }
    lock_time 539071
    outputs
    {
        output
        {
            address_hash 49e282ad0605c1cb63ff45fc34b14357859e8d08
            script "hash160 [49e282ad0605c1cb63ff45fc34b14357859e8d08] equal"
            value 18640
        }
        output
        {
            address_hash 113e1767186f0280174123ad0c22e8929f994c1c
            script "hash160 [113e1767186f0280174123ad0c22e8929f994c1c] equal"
            value 30000
        }
    }
    version 1
}
</code></pre>

<p><strong>% bx fetch-tx -c ~/bitcoin-explorer/bx-mainnet-remote.cfg 50ca26b5a369aadcaa1a18ac6f492e81a451b0e7832db583a7a7677a8cb0e792</strong></p>

<pre><code>transaction
{
    hash 50ca26b5a369aadcaa1a18ac6f492e81a451b0e7832db583a7a7677a8cb0e792
    inputs
    {
        input
        {
            address_hash 62979379f3e415ef86d5dcecf9c93a9930333ce6
            previous_output
            {
                hash dbc6bff3ef644974667316072c6e28e5c58c18e62f8282ff624fde7d179639b2
                index 3
            }
            script [0020a9250a9c4e56b3d822717c37c713d30618f2af8f5932ded48fd6c8b3f0b5ff05]
            sequence 4294967295
        }
    }
    lock_time 0
    outputs
    {
        output
        {
            address_hash 877f4856923528187ab9708660fa201e4282ef8f
            script "dup hash160 [877f4856923528187ab9708660fa201e4282ef8f] equalverify checksig"
            value 10000
        }
        output
        {
            address_hash 70871ecb261f3df9a9d325b33ef6d8acb5074258
            script "hash160 [70871ecb261f3df9a9d325b33ef6d8acb5074258] equal"
            value 212250
        }
    }
    version 1
}
</code></pre>

<p>Upon examination of the two different encumbrance scripts are of P2SH form:</p>

<p>1) script "hash160 [49e282ad0605c1cb63ff45fc34b14357859e8d08] equal"</p>

<p>2) script "hash160 [70871ecb261f3df9a9d325b33ef6d8acb5074258] equal"</p>

<p>the two <strong>address_hash</strong> data values are operated on as follows:</p>

<p><strong>% echo 49e282ad0605c1cb63ff45fc34b14357859e8d08 | bx base58check-encode -v 5</strong>
<code>38Rgbmaxitveg1S8UNbWjwV5UMoBt3PtnG</code></p>

<p><strong>% echo 70871ecb261f3df9a9d325b33ef6d8acb5074258 | bx base58check-encode -v 5</strong>
<code>3Bx1UMJieKFngvBA8m2VqE6s4wXYKWzhkP</code></p>

<p>If a particular addresses were of P2PKH form, replace the <code>-v 5</code> with <code>-v 0</code> in the operations above.</p>

<p>BTW - It looks like the two redeemed P2SH inputs are really both 2 of 2 multisig addresses based upon the examination of the two DER-encoded signatures and knowing the last data elements are script-encoded.</p>

<p><strong>% echo 52210274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8210343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d46352ae | bx script-decode</strong></p>

<pre><code>2 [0274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8] [0343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d463] 2 checkmultisig
</code></pre>

<p><strong>% echo 522103838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b4722103c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d52ae | bx script-decode</strong></p>

<pre><code>2 [03838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b472] [03c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d] 2 checkmultisig
</code></pre>

<p>Bitcoin Explorer kicks butt!! </p>

CC BY-SA 4.0
2019-01-11T00:14:42.873Z
do you know what you are a life saviour. Thanks.
sujoshi
CC BY-SA 4.0
2019-01-11T00:19:54.463Z
You do not need access to the previous transactions to find the input addresses. See my answer below for how to do this.
Thorkil Værge
CC BY-SA 4.0
2019-01-11T04:26:08.753Z
@ThorkilVærge -  You are right since the redeem scripts are both for multisig addresses.  Two or more signatures for a redemption requires the two inputs to be P2SH addresses.  Otherwise, if not **multisig** there is ambiguity whether the inputs are P2PKH or P2SH where version=0 or version=5 respectively to compute the input addresses.
skaht
CC BY-SA 4.0
2019-01-11T08:18:46.567Z
@skaht: I am not familiar with a transaction from where you cannot derive a list of input addresses. Can you give me a more concrete, specific example?
Thorkil Værge
CC BY-SA 4.0
2019-01-15T19:16:02.657Z
@ThorkilVaerge -  I'm not saying input addresses can't be derived, however, a degree of analysis indirection is needed. The issue is without knowing the UTXO locking scripts used fund the TX being analyzed there is typically ambiguity as to how to synthesize the addresses for those inputs.  This is because address version numbers ( 0 or 5 ) are missing in the primary TX's inputs.  Hence, the reason for analyzing the two other secondary TXs, which are the UTXO sources for funding the TX being analyzed.
skaht
CC BY-SA 4.0
2019-01-10T19:06:29.683Z
2019-01-10T19:06:29.683Z
skaht
<p>Addresses are associated with output scripts (scriptPubKeys). This information is not encoded in the transaction, the only information in the input is the txid and index of the output that is being redeemed. In order to do this offline you need to have the previous transaction. </p>

<p>The way they do it for inputs is they look up the previous output that the input is spending in their internal database and get the script from there.</p>

<p>In your example, this is the first input:</p>

<pre><code>    {
        "addresses": [
            "38Rgbmaxitveg1S8UNbWjwV5UMoBt3PtnG"
        ], 
        "age": 539082, 
        "output_index": 0, 
        "output_value": 18640, 
        "prev_hash": "f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4", 
        "script": "2200202dc520822e73d4262000d3b456b16df1d07b0ba9d238f3063379d65840fd38e7",

        "script_type": "pay-to-script-hash", 
        "sequence": 4294967294, 
        "witness": [
            "", 
            "304402202575f8326e510b8213d70a8213ab1a36cd2984b16673ef3579960d0089ad13de022020ec4e78129c084103909acec0319f7d326fff699de142ab354be9570d68dc1701",

            "304402202bc22860e84e0311bbc175940c2b3b5435255dc7ca3fb0d12e5f03df80237b880220536eceee1aace094825f0fd884d057e395102f4e4627188fe6dd5648cdc7a45701",

            "52210274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8210343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d46352ae"
        ]
    },
</code></pre>

<p>So you have to have the full tx with txid <code>f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4</code> in which case you inspect the first output (index 0) and from this output's script <code>OP_HASH160 49e282ad0605c1cb63ff45fc34b14357859e8d08 OP_EQUAL</code> you can derive the address <code>38Rgbmaxitveg1S8UNbWjwV5UMoBt3PtnG</code></p>

CC BY-SA 4.0
2018-09-08T12:20:31.093Z
thank you for your help. :D  i 'm unable to upvote since i'm new to this platform. thanks again.
sujoshi
CC BY-SA 4.0
2019-01-11T00:20:03.913Z
You do not need access to the previous transactions to find the input addresses. See my answer below for how to do this.
Thorkil Værge
CC BY-SA 4.0
2018-09-08T11:50:53.287Z
2018-09-08T11:57:42.757Z
2018-09-08T11:57:42.757Z
Mike D
<p><strong>This can actually also be achieved without access to the previous transactions.</strong></p>
<p>The transaction <code>b0dd3d915a568c9d48e37b3fbfca58ae3276a5dba176fdf30f18af794310cc02</code> is a segwit transaction. And it contains multiple signatures, so it is a multisig transaction. Formally this is called a P2SH-P2WSH transaction.</p>
<p>There are two transaction inputs being spent in this transaction. Each transaction input has a witness field. Each witness field contains four elements, a dummy field (because Bitcoin has some legacy issues), two signature fields, and one witness script which contains the public keys which are used to check if the provided signatures are valid.</p>
<p>These two last elements of the witness fields (the witness scripts) look like this:</p>
<pre><code>52
21
  0274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8
21
  0343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d463
52
ae
</code></pre>
<p>and</p>
<pre><code>52
21
  03838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b472
21
  03c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d
52
ae
</code></pre>
<p><strong>Each witness script has an associated address.</strong> These are the addresses we are looking for, the input addresses. To derive this address, we follow the recipe described on <a href="https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wsh-address" rel="nofollow noreferrer">Bitcoin Core's Segregated Witness Wallet Development Guide</a>. Basically, it says</p>
<pre><code>redeemScript = &quot;0020&quot; + SHA256(witnessScript);
address = base58Enc(&quot;05&quot; + RipeMD160(Sha256(redeemScript)));
</code></pre>
<p>Which yields the two input addresses, <code>38Rgbmaxitveg1S8UNbWjwV5UMoBt3PtnG</code> and <code>3Bx1UMJieKFngvBA8m2VqE6s4wXYKWzhkP</code>.</p>
<p>You should note that this derivation was made much more complicated by the fact that it was a multisig and segwit transaction. In a more regular transaction, like <code>a4453c9e224a0927f2909e49e3a97b31b5aa74a42d99de8cfcdaf293cb2ecbb7</code> you can simply find the public keys of the address and calculate the addresses corresponding to those public keys:</p>
<pre><code>Base58Enc(00 + RipeMD160(SHA256(0x029774feb36d1af279b42a6414e9a702c5e451397671554792c00e5f14bcbce292))) = 1KuK7vSWJCKcidp6WU1Cj3csxKoeTiYYCs 
</code></pre>

CC BY-SA 4.0
2019-01-11T00:18:04.797Z
2023-03-18T16:35:45.187Z
2023-03-18T16:35:45.187Z
Thorkil Værge
<p>I need help to get input addresses from "vin" in offline mode.</p>

<p>I don't know how <a href="https://live.blockcypher.com/btc/decodetx/" rel="noreferrer">https://live.blockcypher.com/btc/decodetx/</a> is doing it.</p>

<p>Example raw transaction:</p>

<p><strong>txn id</strong> : b0dd3d915a568c9d48e37b3fbfca58ae3276a5dba176fdf30f18af794310cc02</p>

<p><strong>raw txn :</strong></p>

<pre><code>01000000000102b4370d52c1e1dc67b0250ef7bd5265146d4def0beacfefd99660a86baf97faf000000000232200202dc520822e73d4262000d3b456b16df1d07b0ba9d238f3063379d65840fd38e7feffffff92e7b08c7a67a7a783b52d83e7b051a4812e496fac181aaadcaa69a3b526ca500100000023220020357bc74e1f825c4628519a3322f2aa9b2c5bd55b523149d4e1f7fe2f273ce7d6feffffff02a08601000000000017a914113e1767186f0280174123ad0c22e8929f994c1c87f4fd01000000000017a9148160a47aeafb68288f0df8551d5d9dddd22a643387040047304402202575f8326e510b8213d70a8213ab1a36cd2984b16673ef3579960d0089ad13de022020ec4e78129c084103909acec0319f7d326fff699de142ab354be9570d68dc170147304402202bc22860e84e0311bbc175940c2b3b5435255dc7ca3fb0d12e5f03df80237b880220536eceee1aace094825f0fd884d057e395102f4e4627188fe6dd5648cdc7a457014752210274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8210343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d46352ae0400473044022042d6861f81b617cfbe51e7efefb59dd990d4c0057b43645d2f006db93b38c59e02204595b7f822546082b0ee1efb6966c97b2d8174c96b670a10bc9d78d3cf7ba99101483045022100bb3a612fe17f261a0c5e9db20a087362c10556571ef54866ab29cfdb94975236022037bebec4c0459bba21656cb36b331313c2dd6008ed7a2479efca659c7fc97c9d0147522103838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b4722103c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d52ae2f3f0800
</code></pre>

<p><strong>Expected "input addresses":</strong></p>

<p>38Rgbmaxitveg1S8UNbWjwV5UMoBt3PtnG</p>

<p>3Bx1UMJieKFngvBA8m2VqE6s4wXYKWzhkP</p>

<p><strong>Thank you.</strong></p>

<address><raw-transaction>
How to extract addresses from input in raw transaction
sujoshi
# How to extract addresses from input in raw transaction

(Asked by: username_0 on 2018-09-08)

I need help to get input addresses from "vin" in offline mode.

I don't know how <https://live.blockcypher.com/btc/decodetx/> is doing it.

Example raw transaction:

**txn id** : b0dd3d915a568c9d48e37b3fbfca58ae3276a5dba176fdf30f18af794310cc02

**raw txn :**

```
01000000000102b4370d52c1e1dc67b0250ef7bd5265146d4def0beacfefd99660a86baf97faf000000000232200202dc520822e73d4262000d3b456b16df1d07b0ba9d238f3063379d65840fd38e7feffffff92e7b08c7a67a7a783b52d83e7b051a4812e496fac181aaadcaa69a3b526ca500100000023220020357bc74e1f825c4628519a3322f2aa9b2c5bd55b523149d4e1f7fe2f273ce7d6feffffff02a08601000000000017a914113e1767186f0280174123ad0c22e8929f994c1c87f4fd01000000000017a9148160a47aeafb68288f0df8551d5d9dddd22a643387040047304402202575f8326e510b8213d70a8213ab1a36cd2984b16673ef3579960d0089ad13de022020ec4e78129c084103909acec0319f7d326fff699de142ab354be9570d68dc170147304402202bc22860e84e0311bbc175940c2b3b5435255dc7ca3fb0d12e5f03df80237b880220536eceee1aace094825f0fd884d057e395102f4e4627188fe6dd5648cdc7a457014752210274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8210343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d46352ae0400473044022042d6861f81b617cfbe51e7efefb59dd990d4c0057b43645d2f006db93b38c59e02204595b7f822546082b0ee1efb6966c97b2d8174c96b670a10bc9d78d3cf7ba99101483045022100bb3a612fe17f261a0c5e9db20a087362c10556571ef54866ab29cfdb94975236022037bebec4c0459bba21656cb36b331313c2dd6008ed7a2479efca659c7fc97c9d0147522103838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b4722103c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d52ae2f3f0800

```

**Expected "input addresses":**

38Rgbmaxitveg1S8UNbWjwV5UMoBt3PtnG

3Bx1UMJieKFngvBA8m2VqE6s4wXYKWzhkP

**Thank you.**

**Tags:** address, raw-transaction


---

## 3 answers

### Answer by username_1 on 2019-01-10. Score: 2 | Accepted answer

The **[bitcoin-exlporer (bx) tool](https://github.com/libbitcoin/libbitcoin-explorer/wiki)** applied below does not yet support the segwit-encoded portion of analyzing a raw hexadecimal transaction (TX). However, the bx commands below can analyze the results offline given the supplied raw TX provided above, and two pertinent TXs associated with the two input UTXOs.

**% echo 01000000000102b4370d52c1e1dc67b0250ef7bd5265146d4def0beacfefd99660a86baf97faf000000000232200202dc520822e73d4262000d3b456b16df1d07b0ba9d238f3063379d65840fd38e7feffffff92e7b08c7a67a7a783b52d83e7b051a4812e496fac181aaadcaa69a3b526ca500100000023220020357bc74e1f825c4628519a3322f2aa9b2c5bd55b523149d4e1f7fe2f273ce7d6feffffff02a08601000000000017a914113e1767186f0280174123ad0c22e8929f994c1c87f4fd01000000000017a9148160a47aeafb68288f0df8551d5d9dddd22a643387040047304402202575f8326e510b8213d70a8213ab1a36cd2984b16673ef3579960d0089ad13de022020ec4e78129c084103909acec0319f7d326fff699de142ab354be9570d68dc170147304402202bc22860e84e0311bbc175940c2b3b5435255dc7ca3fb0d12e5f03df80237b880220536eceee1aace094825f0fd884d057e395102f4e4627188fe6dd5648cdc7a457014752210274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8210343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d46352ae0400473044022042d6861f81b617cfbe51e7efefb59dd990d4c0057b43645d2f006db93b38c59e02204595b7f822546082b0ee1efb6966c97b2d8174c96b670a10bc9d78d3cf7ba99101483045022100bb3a612fe17f261a0c5e9db20a087362c10556571ef54866ab29cfdb94975236022037bebec4c0459bba21656cb36b331313c2dd6008ed7a2479efca659c7fc97c9d0147522103838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b4722103c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d52ae2f3f0800 | bx tx-decode**

```
{
    hash b0dd3d915a568c9d48e37b3fbfca58ae3276a5dba176fdf30f18af794310cc02
    inputs
    {
        input
        {
            address_hash 49e282ad0605c1cb63ff45fc34b14357859e8d08
            previous_output
            {
                hash f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4
                index 0
            }
            script [00202dc520822e73d4262000d3b456b16df1d07b0ba9d238f3063379d65840fd38e7]
            sequence 4294967294
            witness "[] [304402202575f8326e510b8213d70a8213ab1a36cd2984b16673ef3579960d0089ad13de022020ec4e78129c084103909acec0319f7d326fff699de142ab354be9570d68dc1701] [304402202bc22860e84e0311bbc175940c2b3b5435255dc7ca3fb0d12e5f03df80237b880220536eceee1aace094825f0fd884d057e395102f4e4627188fe6dd5648cdc7a45701] [52210274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8210343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d46352ae]"
        }
        input
        {
            address_hash 70871ecb261f3df9a9d325b33ef6d8acb5074258
            previous_output
            {
                hash 50ca26b5a369aadcaa1a18ac6f492e81a451b0e7832db583a7a7677a8cb0e792
                index 1
            }
            script [0020357bc74e1f825c4628519a3322f2aa9b2c5bd55b523149d4e1f7fe2f273ce7d6]
            sequence 4294967294
            witness "[] [3044022042d6861f81b617cfbe51e7efefb59dd990d4c0057b43645d2f006db93b38c59e02204595b7f822546082b0ee1efb6966c97b2d8174c96b670a10bc9d78d3cf7ba99101] [3045022100bb3a612fe17f261a0c5e9db20a087362c10556571ef54866ab29cfdb94975236022037bebec4c0459bba21656cb36b331313c2dd6008ed7a2479efca659c7fc97c9d01] [522103838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b4722103c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d52ae]"
        }
    }
    lock_time 540463
    outputs
    {
        output
        {
            address_hash 113e1767186f0280174123ad0c22e8929f994c1c
            script "hash160 [113e1767186f0280174123ad0c22e8929f994c1c] equal"
            value 100000
        }
        output
        {
            address_hash 8160a47aeafb68288f0df8551d5d9dddd22a6433
            script "hash160 [8160a47aeafb68288f0df8551d5d9dddd22a6433] equal"
            value 130548
        }
    }
    version 1
}

```

Then one needs to examine the encumbrance scripts associated with the following to affirm determine if they P2PKH or P2SH address types:

1) transaction ID f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4 and index 0

2) transaction ID 50ca26b5a369aadcaa1a18ac6f492e81a451b0e7832db583a7a7677a8cb0e792 and index 1

**% bx fetch-tx -c ~/bitcoin-explorer/bx-mainnet-remote.cfg f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4**

```
transaction
{
    hash f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4
    inputs
    {
        input
        {
            address_hash 40ef0e3af404842b44912f6a65ca4adfb8f93a1a
            previous_output
            {
                hash f0eda490f5e8c3096b74b66524ff9c7b6fa1b9d4280e8372476af1d202a8b360
                index 1
            }
            script [0020de730ce4f827ac7c63ea8c9a47419875eacaf167f9391eb5d30817a181aca8d3]
            sequence 4294967294
        }
    }
    lock_time 539071
    outputs
    {
        output
        {
            address_hash 49e282ad0605c1cb63ff45fc34b14357859e8d08
            script "hash160 [49e282ad0605c1cb63ff45fc34b14357859e8d08] equal"
            value 18640
        }
        output
        {
            address_hash 113e1767186f0280174123ad0c22e8929f994c1c
            script "hash160 [113e1767186f0280174123ad0c22e8929f994c1c] equal"
            value 30000
        }
    }
    version 1
}

```

**% bx fetch-tx -c ~/bitcoin-explorer/bx-mainnet-remote.cfg 50ca26b5a369aadcaa1a18ac6f492e81a451b0e7832db583a7a7677a8cb0e792**

```
transaction
{
    hash 50ca26b5a369aadcaa1a18ac6f492e81a451b0e7832db583a7a7677a8cb0e792
    inputs
    {
        input
        {
            address_hash 62979379f3e415ef86d5dcecf9c93a9930333ce6
            previous_output
            {
                hash dbc6bff3ef644974667316072c6e28e5c58c18e62f8282ff624fde7d179639b2
                index 3
            }
            script [0020a9250a9c4e56b3d822717c37c713d30618f2af8f5932ded48fd6c8b3f0b5ff05]
            sequence 4294967295
        }
    }
    lock_time 0
    outputs
    {
        output
        {
            address_hash 877f4856923528187ab9708660fa201e4282ef8f
            script "dup hash160 [877f4856923528187ab9708660fa201e4282ef8f] equalverify checksig"
            value 10000
        }
        output
        {
            address_hash 70871ecb261f3df9a9d325b33ef6d8acb5074258
            script "hash160 [70871ecb261f3df9a9d325b33ef6d8acb5074258] equal"
            value 212250
        }
    }
    version 1
}

```

Upon examination of the two different encumbrance scripts are of P2SH form:

1) script "hash160 [49e282ad0605c1cb63ff45fc34b14357859e8d08] equal"

2) script "hash160 [70871ecb261f3df9a9d325b33ef6d8acb5074258] equal"

the two **address\_hash** data values are operated on as follows:

**% echo 49e282ad0605c1cb63ff45fc34b14357859e8d08 | bx base58check-encode -v 5**
`38Rgbmaxitveg1S8UNbWjwV5UMoBt3PtnG`

**% echo 70871ecb261f3df9a9d325b33ef6d8acb5074258 | bx base58check-encode -v 5**
`3Bx1UMJieKFngvBA8m2VqE6s4wXYKWzhkP`

If a particular addresses were of P2PKH form, replace the `-v 5` with `-v 0` in the operations above.

BTW - It looks like the two redeemed P2SH inputs are really both 2 of 2 multisig addresses based upon the examination of the two DER-encoded signatures and knowing the last data elements are script-encoded.

**% echo 52210274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8210343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d46352ae | bx script-decode**

```
2 [0274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8] [0343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d463] 2 checkmultisig

```

**% echo 522103838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b4722103c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d52ae | bx script-decode**

```
2 [03838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b472] [03c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d] 2 checkmultisig

```

Bitcoin Explorer kicks butt!!

> **Comments:**
> **username_0**: do you know what you are a life saviour. Thanks.  
> **username_2**: You do not need access to the previous transactions to find the input addresses. See my answer below for how to do this.  
> **username_1**: @username_2 -  You are right since the redeem scripts are both for multisig addresses.  Two or more signatures for a redemption requires the two inputs to be P2SH addresses.  Otherwise, if not **multisig** there is ambiguity whether the inputs are P2PKH or P2SH where version=0 or version=5 respectively to compute the input addresses.  
> **username_2**: @username_1: I am not familiar with a transaction from where you cannot derive a list of input addresses. Can you give me a more concrete, specific example?  
> **username_1**: @ThorkilVaerge -  I'm not saying input addresses can't be derived, however, a degree of analysis indirection is needed. The issue is without knowing the UTXO locking scripts used fund the TX being analyzed there is typically ambiguity as to how to synthesize the addresses for those inputs.  This is because address version numbers ( 0 or 5 ) are missing in the primary TX's inputs.  Hence, the reason for analyzing the two other secondary TXs, which are the UTXO sources for funding the TX being analyzed.  

---

### Answer by username_3 on 2018-09-08. Score: 6

Addresses are associated with output scripts (scriptPubKeys). This information is not encoded in the transaction, the only information in the input is the txid and index of the output that is being redeemed. In order to do this offline you need to have the previous transaction.

The way they do it for inputs is they look up the previous output that the input is spending in their internal database and get the script from there.

In your example, this is the first input:

```
    {
        "addresses": [
            "38Rgbmaxitveg1S8UNbWjwV5UMoBt3PtnG"
        ], 
        "age": 539082, 
        "output_index": 0, 
        "output_value": 18640, 
        "prev_hash": "f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4", 
        "script": "2200202dc520822e73d4262000d3b456b16df1d07b0ba9d238f3063379d65840fd38e7",

        "script_type": "pay-to-script-hash", 
        "sequence": 4294967294, 
        "witness": [
            "", 
            "304402202575f8326e510b8213d70a8213ab1a36cd2984b16673ef3579960d0089ad13de022020ec4e78129c084103909acec0319f7d326fff699de142ab354be9570d68dc1701",

            "304402202bc22860e84e0311bbc175940c2b3b5435255dc7ca3fb0d12e5f03df80237b880220536eceee1aace094825f0fd884d057e395102f4e4627188fe6dd5648cdc7a45701",

            "52210274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8210343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d46352ae"
        ]
    },

```

So you have to have the full tx with txid `f0fa97af6ba86096d9efcfea0bef4d6d146552bdf70e25b067dce1c1520d37b4` in which case you inspect the first output (index 0) and from this output's script `OP_HASH160 49e282ad0605c1cb63ff45fc34b14357859e8d08 OP_EQUAL` you can derive the address `38Rgbmaxitveg1S8UNbWjwV5UMoBt3PtnG`

> **Comments:**
> **username_0**: thank you for your help. :D  i 'm unable to upvote since i'm new to this platform. thanks again.  
> **username_2**: You do not need access to the previous transactions to find the input addresses. See my answer below for how to do this.  

---

### Answer by username_2 on 2019-01-11. Score: 1

**This can actually also be achieved without access to the previous transactions.**

The transaction `b0dd3d915a568c9d48e37b3fbfca58ae3276a5dba176fdf30f18af794310cc02` is a segwit transaction. And it contains multiple signatures, so it is a multisig transaction. Formally this is called a P2SH-P2WSH transaction.

There are two transaction inputs being spent in this transaction. Each transaction input has a witness field. Each witness field contains four elements, a dummy field (because Bitcoin has some legacy issues), two signature fields, and one witness script which contains the public keys which are used to check if the provided signatures are valid.

These two last elements of the witness fields (the witness scripts) look like this:

```
52
21
  0274ecb4e28e6b7be314d844bb7561b605d537106f7f5c3eaba31a8cd3dd0097c8
21
  0343ed9c58350b4013b3c9a02da2148d59e8109a90f0fa0ea77d31b8570990d463
52
ae

```

and

```
52
21
  03838edaeadeed0e9f660e725970787b69ad4926afe1f19626d5476d356cb3b472
21
  03c37f3b264f674c6c2e273e06da7fb7fe720be6828f251c71d0cb10e349d0222d
52
ae

```

**Each witness script has an associated address.** These are the addresses we are looking for, the input addresses. To derive this address, we follow the recipe described on [Bitcoin Core's Segregated Witness Wallet Development Guide](https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wsh-address). Basically, it says

```
redeemScript = "0020" + SHA256(witnessScript);
address = base58Enc("05" + RipeMD160(Sha256(redeemScript)));

```

Which yields the two input addresses, `38Rgbmaxitveg1S8UNbWjwV5UMoBt3PtnG` and `3Bx1UMJieKFngvBA8m2VqE6s4wXYKWzhkP`.

You should note that this derivation was made much more complicated by the fact that it was a multisig and segwit transaction. In a more regular transaction, like `a4453c9e224a0927f2909e49e3a97b31b5aa74a42d99de8cfcdaf293cb2ecbb7` you can simply find the public keys of the address and calculate the addresses corresponding to those public keys:

```
Base58Enc(00 + RipeMD160(SHA256(0x029774feb36d1af279b42a6414e9a702c5e451397671554792c00e5f14bcbce292))) = 1KuK7vSWJCKcidp6WU1Cj3csxKoeTiYYCs 

```


---

