Post
Topic
Board Bitcoin Technical Support
Merits 16 from 8 users
Re: Sign Transaction Bitcoin with Openssl
by
BrewMaster
on 16/02/2020, 15:34:36 UTC
⭐ Merited by bones261 (4) ,malevolent (3) ,joniboini (2) ,OgNasty (2) ,o_e_l_e_o (2) ,Heisenberg_Hunter (1) ,mocacinno (1) ,DdmrDdmr (1)
I know that I have to do double sha256
Code:
    $ printf 0200000001bc010c04e1c44a991760fa1cb7af1076bf755077d1cba60d3d4ca3f0de670d210000000000ffffffff01c0aff629010000001976a914f6b61a355d427c892e51bdb261d4f56c4e93b16f88ac00000000 | xxd -r -p | sha256sum -b | xxd -r -p | sha256sum -b > a.txt

this is your mistake.
in bitcoin you don't just hash the raw transaction itself, you have to first modify it then hash the modified result.
this hex is missing 2 things:
1. the scriptsig is empty which should have been replaced by the scriptpub of the input you are spending
2. the sighashtype at the end which is a 4 byte integer in little endian order.
you can find more information on bitcoin wiki's checksig or on SE:
https://bitcoin.stackexchange.com/questions/32628/redeeming-a-raw-transaction-step-by-step-example-required

these steps are more complicated for different script types though.