<p>Here is how things can be done backwards.  Unfortunately, the bitcoin-explorer (bx) verify mechanism works a little differently but somewhat similar to what you were expecting.  Step 4 below might provide details that might be useful for what you are doing. Step 5 below completes the validation offline.</p>

<p><strong>1. Here is the easy way to compute transaction IDs from the raw hexadecimal transactions.</strong></p>

<p>% echo 01000000018a8a9f938c251be60da2711c6bf168c66213fae8e26251fcec47f9a41d0e71e3020000006b483045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d012103c0f217eb4428c61d47d8aa084a28c3d3d26f43b6569283f08fec5451a5fc8c98ffffffff0200803801000000001976a914d2c6b9c7f146ea4039e6ae67904eb94d479b7ed688ac06d79e460e0000001976a914b85f8cde95fe9b30872e49d5b961a4af5d07518688ac00000000 | bx <a href="https://github.com/libbitcoin/libbitcoin-explorer/wiki/bx-bitcoin256" rel="nofollow noreferrer">bitcoin256</a></p>

<p><code>9b4912711de5e258a74a529227f43647bc3b2304212fb508c5f8e910d5986270</code></p>

<p><strong>2. Here are two means (1st is offline, 2nd is online) to extract the Endorsement/Signature and associated Public Key used for the TX_ID 9b4912711de5e258a74a529227f43647bc3b2304212fb508c5f8e910d5986270 input:</strong></p>

<p>% echo 01000000018a8a9f938c251be60da2711c6bf168c66213fae8e26251fcec47f9a41d0e71e3020000006b483045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d012103c0f217eb4428c61d47d8aa084a28c3d3d26f43b6569283f08fec5451a5fc8c98ffffffff0200803801000000001976a914d2c6b9c7f146ea4039e6ae67904eb94d479b7ed688ac06d79e460e0000001976a914b85f8cde95fe9b30872e49d5b961a4af5d07518688ac00000000 | bx <a href="https://github.com/libbitcoin/libbitcoin-explorer/wiki/bx-tx-decode" rel="nofollow noreferrer">tx-decode</a></p>

<p>or </p>

<p>% bx <a href="https://github.com/libbitcoin/libbitcoin-explorer/wiki/bx-fetch-tx" rel="nofollow noreferrer">fetch-tx</a> -c ~/bitcoin-explorer/bx-mainnet-remote.cfg 9b4912711de5e258a74a529227f43647bc3b2304212fb508c5f8e910d5986270</p>

<p>that both yield:</p>

<pre><code>transaction
{
    hash 9b4912711de5e258a74a529227f43647bc3b2304212fb508c5f8e910d5986270
    inputs
    {
        input
        {
            address_hash a0d48c129cfde8f124a16f4d69bc47fd7fb5780d
            previous_output
            {
                hash e3710e1da4f947ecfc5162e2e8fa1362c668f16b1c71a20de61b258c939f8a8a
                index 2
            }
            script "[3045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d01] [03c0f217eb4428c61d47d8aa084a28c3d3d26f43b6569283f08fec5451a5fc8c98]"
            sequence 4294967295
        }
    }
    lock_time 0
    outputs
    {
        output
        {
            address_hash d2c6b9c7f146ea4039e6ae67904eb94d479b7ed6
            script "dup hash160 [d2c6b9c7f146ea4039e6ae67904eb94d479b7ed6] equalverify checksig"
            value 20480000
        }
        output
        {
            address_hash b85f8cde95fe9b30872e49d5b961a4af5d075186
            script "dup hash160 [b85f8cde95fe9b30872e49d5b961a4af5d075186] equalverify checksig"
            value 61314356998
        }
    }
    version 1
}
</code></pre>

<p><strong><em>Distinguished Encoding Rules (DER) formatted Signature =</em></strong> <code>3045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d01</code></p>

<p><strong>R =</strong></p>

<p>% echo 3045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d01 | cut -c 9-74
<code>00ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed429</code> </p>

<p><strong>S =</strong></p>

<p>% echo 3045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d01 | cut -c 79-142
<code>4efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d</code></p>

<p><strong><em>Pubkey =</em></strong> <code>03c0f217eb4428c61d47d8aa084a28c3d3d26f43b6569283f08fec5451a5fc8c98</code></p>

<p><strong>3. The 3rd output of TXID e3710e1da4f947ecfc5162e2e8fa1362c668f16b1c71a20de61b258c939f8a8a contains the original input script that was signed, requires an additional online query:</strong></p>

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

<pre><code>transaction
{
    hash e3710e1da4f947ecfc5162e2e8fa1362c668f16b1c71a20de61b258c939f8a8a
    inputs
    {
        input
        {
            address_hash 3480cd7a92d09974aacc473512ca80a686249498
            previous_output
            {
                hash 4b7b945088ad38de258490d02bdca724548818e1ad184d0e00a2d4d1e82229c8
                index 0
            }
            script "[3046022100da2122351174582ca4f8b9cfc2567bd2c95c3f30be13ce0f20422ba6c2d55806022100af211740671144cc8cbce04e8028e60eb1028af661a8eba77430e4a8615925da01] [02416953ece00bbc3a1ebca108c8961abae0bcc613ecf838bb0e5799202fbe7ae4]"
            sequence 4294967295
        }
    }
    lock_time 0
    outputs
    {
        output
        {
            address_hash ead65b0c5d7abc0af467ae2f34ed1b84a6662fda
            script "dup hash160 [ead65b0c5d7abc0af467ae2f34ed1b84a6662fda] equalverify checksig"
            value 12557630
        }
        output
        {
            address_hash 59cca2f8c91a9784c6c38da5a10f00644238b527
            script "dup hash160 [59cca2f8c91a9784c6c38da5a10f00644238b527] equalverify checksig"
            value 10100000
        }
        output
        {
            address_hash a0d48c129cfde8f124a16f4d69bc47fd7fb5780d
            script "dup hash160 [a0d48c129cfde8f124a16f4d69bc47fd7fb5780d] equalverify checksig"
            value 61334886998
        }
    }
    version 1
}
</code></pre>

<p><strong><em>ASCII encoded script =</em></strong> <code>"dup hash160 [a0d48c129cfde8f124a16f4d69bc47fd7fb5780d] equalverify checksig"</code></p>

<p>and computing the corresponding P2PKH address:</p>

<p>% echo a0d48c129cfde8f124a16f4d69bc47fd7fb5780d | bx <a href="https://github.com/libbitcoin/libbitcoin-explorer/wiki/bx-address-encode" rel="nofollow noreferrer">address-encode</a> -v 0</p>

<p><code>1FfPjjFG1uoA62yiTsje8biYYvEhf8puQP</code></p>

<p><strong>4. For self awareness, compute Hex encoded script and associated sha256 value:</strong></p>

<p>% echo "dup hash160 [a0d48c129cfde8f124a16f4d69bc47fd7fb5780d] equalverify checksig" | bx <a href="https://github.com/libbitcoin/libbitcoin-explorer/wiki/bx-script-encode" rel="nofollow noreferrer">script-encode</a></p>

<p><code>76a914a0d48c129cfde8f124a16f4d69bc47fd7fb5780d88ac</code></p>

<p>% echo 76a914a0d48c129cfde8f124a16f4d69bc47fd7fb5780d88ac | bx sha256
<code>0d9288118ccdc74e6ce85ced746aa48afbd30eb70f58e4ce009a78dd96faf33d</code></p>

<p><strong>5. Confirm signature is valid using an offline command:</strong></p>

<p>% echo 01000000018a8a9f938c251be60da2711c6bf168c66213fae8e26251fcec47f9a41d0e71e3020000006b483045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d012103c0f217eb4428c61d47d8aa084a28c3d3d26f43b6569283f08fec5451a5fc8c98ffffffff0200803801000000001976a914d2c6b9c7f146ea4039e6ae67904eb94d479b7ed688ac06d79e460e0000001976a914b85f8cde95fe9b30872e49d5b961a4af5d07518688ac00000000 | bx <a href="https://github.com/libbitcoin/libbitcoin-explorer/wiki/bx-input-validate" rel="nofollow noreferrer">input-validate</a> -i 0 03c0f217eb4428c61d47d8aa084a28c3d3d26f43b6569283f08fec5451a5fc8c98 "dup hash160 [a0d48c129cfde8f124a16f4d69bc47fd7fb5780d] equalverify checksig" 3045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d01</p>

<p><code>The endorsement is valid.</code></p>

CC BY-SA 4.0
2019-02-24T23:20:07.737Z
**This Q does NOT want txid** but rather the hash used in the signature (and verification), which is different, as the Q says and the linked dupes 4 years ago correctly explain.
dave_thompson_085
CC BY-SA 4.0
2019-02-25T22:21:01.507Z
@dave_thompson_085 - Is this better?
skaht
CC BY-SA 4.0
2019-02-24T04:45:00.023Z
2019-02-25T21:44:21.660Z
2019-02-25T21:44:21.660Z
skaht
<p>If I have the public key and signature for a transaction how do I get the hash value that is used in verify(hash, sig, pubkey). I want to know how to work backwards from a raw transaction to get it,  not how to build it.</p>

<p>My question is basically this one </p>

<p><a href="https://bitcoin.stackexchange.com/questions/16772/how-to-verify-the-signature-of-a-raw-transaction">How to verify the signature of a raw transaction</a></p>

<p>But the answer given I think is for getting the Transaction ID hash which I have tried and it doesn't work. </p>

CC BY-SA 3.0
2015-02-27T19:25:33.167Z
possible duplicate of http://bitcoin.stackexchange.com/questions/9300/signature-in-scriptsig
Nick ODell
CC BY-SA 3.0
2015-02-27T23:44:28.933Z
I think [this question](http://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx) might help you to do the exact steps. But yes, it's been asked before.
Jimmy Song
CC BY-SA 3.0
2018-04-21T18:42:14.617Z
And for historical completeness (while I was searching for some keywords), @amaclin provided a step by step approach here: https://bitcoin.stackexchange.com/questions/32305/how-does-the-ecdsa-verification-algorithm-work-during-transaction
pebwindkraft
CC BY-SA 4.0
2020-12-17T10:24:03.173Z
Does this answer your question? [How does the ECDSA verification algorithm work during transaction?](https://bitcoin.stackexchange.com/questions/32305/how-does-the-ecdsa-verification-algorithm-work-during-transaction)
Antoine Poinsot
<signature><hash><ecdsa>
How do I get hash to verify transaction?
KRiley
# How do I get hash to verify transaction?

(Asked by: username_0 on 2015-02-27)

If I have the public key and signature for a transaction how do I get the hash value that is used in verify(hash, sig, pubkey). I want to know how to work backwards from a raw transaction to get it, not how to build it.

My question is basically this one

[How to verify the signature of a raw transaction](https://bitcoin.stackexchange.com/questions/16772/how-to-verify-the-signature-of-a-raw-transaction)

But the answer given I think is for getting the Transaction ID hash which I have tried and it doesn't work.

**Tags:** signature, hash, ecdsa

> **Comments:**
> **username_1**: possible duplicate of http://bitcoin.stackexchange.com/questions/9300/signature-in-scriptsig  
> **username_2**: I think [this question](http://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx) might help you to do the exact steps. But yes, it's been asked before.  
> **username_3**: And for historical completeness (while I was searching for some keywords), @amaclin provided a step by step approach here: https://bitcoin.stackexchange.com/questions/32305/how-does-the-ecdsa-verification-algorithm-work-during-transaction  
> **username_4**: Does this answer your question? [How does the ECDSA verification algorithm work during transaction?](https://bitcoin.stackexchange.com/questions/32305/how-does-the-ecdsa-verification-algorithm-work-during-transaction)  

---

## 1 answers

### Answer by username_5 on 2019-02-24. Score: 0

Here is how things can be done backwards.  Unfortunately, the bitcoin-explorer (bx) verify mechanism works a little differently but somewhat similar to what you were expecting.  Step 4 below might provide details that might be useful for what you are doing. Step 5 below completes the validation offline.
1. Here is the easy way to compute transaction IDs from the raw hexadecimal transactions.
% echo 01000000018a8a9f938c251be60da2711c6bf168c66213fae8e26251fcec47f9a41d0e71e3020000006b483045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d012103c0f217eb4428c61d47d8aa084a28c3d3d26f43b6569283f08fec5451a5fc8c98ffffffff0200803801000000001976a914d2c6b9c7f146ea4039e6ae67904eb94d479b7ed688ac06d79e460e0000001976a914b85f8cde95fe9b30872e49d5b961a4af5d07518688ac00000000 | bx bitcoin256
9b4912711de5e258a74a529227f43647bc3b2304212fb508c5f8e910d5986270
2. Here are two means (1st is offline, 2nd is online) to extract the Endorsement/Signature and associated Public Key used for the TX_ID 9b4912711de5e258a74a529227f43647bc3b2304212fb508c5f8e910d5986270 input:
% echo 01000000018a8a9f938c251be60da2711c6bf168c66213fae8e26251fcec47f9a41d0e71e3020000006b483045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d012103c0f217eb4428c61d47d8aa084a28c3d3d26f43b6569283f08fec5451a5fc8c98ffffffff0200803801000000001976a914d2c6b9c7f146ea4039e6ae67904eb94d479b7ed688ac06d79e460e0000001976a914b85f8cde95fe9b30872e49d5b961a4af5d07518688ac00000000 | bx tx-decode
or 
% bx fetch-tx -c ~/bitcoin-explorer/bx-mainnet-remote.cfg 9b4912711de5e258a74a529227f43647bc3b2304212fb508c5f8e910d5986270
that both yield:
transaction
{
    hash 9b4912711de5e258a74a529227f43647bc3b2304212fb508c5f8e910d5986270
    inputs
    {
        input
        {
            address_hash a0d48c129cfde8f124a16f4d69bc47fd7fb5780d
            previous_output
            {
                hash e3710e1da4f947ecfc5162e2e8fa1362c668f16b1c71a20de61b258c939f8a8a
                index 2
            }
            script "[3045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d01] [03c0f217eb4428c61d47d8aa084a28c3d3d26f43b6569283f08fec5451a5fc8c98]"
            sequence 4294967295
        }
    }
    lock_time 0
    outputs
    {
        output
        {
            address_hash d2c6b9c7f146ea4039e6ae67904eb94d479b7ed6
            script "dup hash160 [d2c6b9c7f146ea4039e6ae67904eb94d479b7ed6] equalverify checksig"
            value 20480000
        }
        output
        {
            address_hash b85f8cde95fe9b30872e49d5b961a4af5d075186
            script "dup hash160 [b85f8cde95fe9b30872e49d5b961a4af5d075186] equalverify checksig"
            value 61314356998
        }
    }
    version 1
}

Distinguished Encoding Rules (DER) formatted Signature = 3045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d01
R =
% echo 3045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d01 | cut -c 9-74
00ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed429 
S =
% echo 3045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d01 | cut -c 79-142
4efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d
Pubkey = 03c0f217eb4428c61d47d8aa084a28c3d3d26f43b6569283f08fec5451a5fc8c98
3. The 3rd output of TXID e3710e1da4f947ecfc5162e2e8fa1362c668f16b1c71a20de61b258c939f8a8a contains the original input script that was signed, requires an additional online query:
% bx fetch-tx -c ~/bitcoin-explorer/bx-mainnet-remote.cfg e3710e1da4f947ecfc5162e2e8fa1362c668f16b1c71a20de61b258c939f8a8a
transaction
{
    hash e3710e1da4f947ecfc5162e2e8fa1362c668f16b1c71a20de61b258c939f8a8a
    inputs
    {
        input
        {
            address_hash 3480cd7a92d09974aacc473512ca80a686249498
            previous_output
            {
                hash 4b7b945088ad38de258490d02bdca724548818e1ad184d0e00a2d4d1e82229c8
                index 0
            }
            script "[3046022100da2122351174582ca4f8b9cfc2567bd2c95c3f30be13ce0f20422ba6c2d55806022100af211740671144cc8cbce04e8028e60eb1028af661a8eba77430e4a8615925da01] [02416953ece00bbc3a1ebca108c8961abae0bcc613ecf838bb0e5799202fbe7ae4]"
            sequence 4294967295
        }
    }
    lock_time 0
    outputs
    {
        output
        {
            address_hash ead65b0c5d7abc0af467ae2f34ed1b84a6662fda
            script "dup hash160 [ead65b0c5d7abc0af467ae2f34ed1b84a6662fda] equalverify checksig"
            value 12557630
        }
        output
        {
            address_hash 59cca2f8c91a9784c6c38da5a10f00644238b527
            script "dup hash160 [59cca2f8c91a9784c6c38da5a10f00644238b527] equalverify checksig"
            value 10100000
        }
        output
        {
            address_hash a0d48c129cfde8f124a16f4d69bc47fd7fb5780d
            script "dup hash160 [a0d48c129cfde8f124a16f4d69bc47fd7fb5780d] equalverify checksig"
            value 61334886998
        }
    }
    version 1
}

ASCII encoded script = "dup hash160 [a0d48c129cfde8f124a16f4d69bc47fd7fb5780d] equalverify checksig"
and computing the corresponding P2PKH address:
% echo a0d48c129cfde8f124a16f4d69bc47fd7fb5780d | bx address-encode -v 0
1FfPjjFG1uoA62yiTsje8biYYvEhf8puQP
4. For self awareness, compute Hex encoded script and associated sha256 value:
% echo "dup hash160 [a0d48c129cfde8f124a16f4d69bc47fd7fb5780d] equalverify checksig" | bx script-encode
76a914a0d48c129cfde8f124a16f4d69bc47fd7fb5780d88ac
% echo 76a914a0d48c129cfde8f124a16f4d69bc47fd7fb5780d88ac | bx sha256
0d9288118ccdc74e6ce85ced746aa48afbd30eb70f58e4ce009a78dd96faf33d
5. Confirm signature is valid using an offline command:
% echo 01000000018a8a9f938c251be60da2711c6bf168c66213fae8e26251fcec47f9a41d0e71e3020000006b483045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d012103c0f217eb4428c61d47d8aa084a28c3d3d26f43b6569283f08fec5451a5fc8c98ffffffff0200803801000000001976a914d2c6b9c7f146ea4039e6ae67904eb94d479b7ed688ac06d79e460e0000001976a914b85f8cde95fe9b30872e49d5b961a4af5d07518688ac00000000 | bx input-validate -i 0 03c0f217eb4428c61d47d8aa084a28c3d3d26f43b6569283f08fec5451a5fc8c98 "dup hash160 [a0d48c129cfde8f124a16f4d69bc47fd7fb5780d] equalverify checksig" 3045022100ad775acd2d0b14904771c28754e0e510ecd8af842732c5c15a0899d1e28ed42902204efb34805a958174f6a6273444cde7f97cf38cec0d96d17c7921490f58e6379d01
The endorsement is valid.

> **Comments:**
> **username_6**: **This Q does NOT want txid** but rather the hash used in the signature (and verification), which is different, as the Q says and the linked dupes 4 years ago correctly explain.  
> **username_5**: @username_6 - Is this better?  

---

