Author

Topic: get txid from signed tx hash (Read 1055 times)

legendary
Activity: 1456
Merit: 1076
I may write code in exchange for bitcoins.
October 20, 2015, 01:34:56 PM
#4
I will just quote this here, because it answers the question and will get lost in the other thread.

Thanks,  dooglus, I was helping FreeHealthCare to deposit a paper wallet and so I pushed the tx through your page and I wanted to be able to tell him, "here ya go: TXID".  I ended up finding it by using a block explorer and looking for his/her deposit address.   Just that that's what prompted the question.  Thanks again for the explanation.  I actually went and asked about how to calculate it in the Technical Discussion board, perhaps someone there can explain why its not coming out the way you expected.

It's because you don't just sha256 it, you sha256 it twice, then reverse the result!

Code:
$ clamd getrawtransaction 512f2e27b233eee9c28ac0f12a653ca1b6e1ef76b8214915d7865dda0b51dfc0 | 
    xxd -r -p |              # convert hex to binary
    sha256sum |              # hash it
    xxd -r -p |              # convert hex to binary
    sha256sum |              # hash it
    awk '{print $1}' |       # keep just the hash:    01234567
    rev |                    # reverse it:            76543210
    sed -E 's/(.)(.)/\2\1/g' # switch adjacent bytes: 67452301
512f2e27b233eee9c28ac0f12a653ca1b6e1ef76b8214915d7865dda0b51dfc0

Edit: I learned this from https://en.bitcoin.it/wiki/Dump_format#General_note_about_hashes - and found that page by googling for 9a538906e6466ebd2617d321f71bc94e56056ce213d366773699e28158e00614, which is what Bitcoin gives when you hash a single 00 byte (which is what I got when I serialized an empty string).


Thanks again, Shorena, I just looked closer and I hadn't seen that dooglus had edited his post to find the answer---I had only seen the earlier version of his post which basically said he wasn't sure why it wasn't working.  Cheers!

Oh yah, and massive thanks to dooglus for figuring it out and showing the example in exactly the environment I was looking for.
copper member
Activity: 1498
Merit: 1499
No I dont escrow anymore.
October 16, 2015, 04:48:15 AM
#3
I will just quote this here, because it answers the question and will get lost in the other thread.

Thanks,  dooglus, I was helping FreeHealthCare to deposit a paper wallet and so I pushed the tx through your page and I wanted to be able to tell him, "here ya go: TXID".  I ended up finding it by using a block explorer and looking for his/her deposit address.   Just that that's what prompted the question.  Thanks again for the explanation.  I actually went and asked about how to calculate it in the Technical Discussion board, perhaps someone there can explain why its not coming out the way you expected.

It's because you don't just sha256 it, you sha256 it twice, then reverse the result!

Code:
$ clamd getrawtransaction 512f2e27b233eee9c28ac0f12a653ca1b6e1ef76b8214915d7865dda0b51dfc0 | 
    xxd -r -p |              # convert hex to binary
    sha256sum |              # hash it
    xxd -r -p |              # convert hex to binary
    sha256sum |              # hash it
    awk '{print $1}' |       # keep just the hash:    01234567
    rev |                    # reverse it:            76543210
    sed -E 's/(.)(.)/\2\1/g' # switch adjacent bytes: 67452301
512f2e27b233eee9c28ac0f12a653ca1b6e1ef76b8214915d7865dda0b51dfc0

Edit: I learned this from https://en.bitcoin.it/wiki/Dump_format#General_note_about_hashes - and found that page by googling for 9a538906e6466ebd2617d321f71bc94e56056ce213d366773699e28158e00614, which is what Bitcoin gives when you hash a single 00 byte (which is what I got when I serialized an empty string).
hero member
Activity: 520
Merit: 522
Developer - EthicHacker - BTC enthusiast
October 16, 2015, 03:31:23 AM
#2
Hello tspacepilot,

from what i know the signed tx must be send --> and the return value of the
Code:
sendrawtransaction()
will then be the txid or otherwise an error if the tx is invalid.

#EDIT: below answer from shorena answers your question how to calculate the txid, without broadcasting.

ca333
legendary
Activity: 1456
Merit: 1076
I may write code in exchange for bitcoins.
October 15, 2015, 08:27:43 PM
#1
I think this is an easy question but I couldn't turn it up by searching on the wiki, so I thought I'd just ask here.  Assuming I have the raw hex of a signed transaction, how do I get the txid?  I tried:

echo -n "01234567890abcdefrawhexofsignedtransactioninherefedcba09876543210" | sha256sum

and that didn't seem to be it.  I also tried:

cho -n "01234567890abcdefrawhexofsignedtransactioninherefedcba09876543210" | sha256sum | sha256sum

and that didn't seem to be it either.

Thanks in advance, you wizards!
Jump to: