Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: zoltanb on January 04, 2021, 09:59:42 PM



Title: bitcoin-cli cold sign raw transaction
Post by: zoltanb on January 04, 2021, 09:59:42 PM
I am having problems offline signing a raw transaction I generated from bitcoin-cli listunspent command.
So, I generated the raw transaction with 1 input (bc1a...) and 1 output (bc1b...).
I then used the hash on my offline wallet (no blockchain data at all, just the bitcoin-cli client and the passphrased wallet.dat). When I issued the command:
"bitcoin-cli signrawtransactionwithwallet hex"
I got this response:
"Input not found or already spent"

Then, I passed to the signrawtransactionwithwallet hex command the txid, vout and scriptpubkey as explained here: https://bitcointalk.org/index.php?topic=2585018.0

But now I receive: "Unable to sign input, missing keys"

I am 100% sure that the input I am trying to spend belongs to an address (bc1a...) generated on the offline wallet I am using to sign the transaction.

What am I doing wrong?


Title: Re: bitcoin-cli cold sign raw transaction
Post by: NotATether on January 04, 2021, 10:33:16 PM
signrawtransactionwithwallet isn't going to work on an offline wallet because it does not know any of the inputs that are being spent hence the "Input not found" part of the error.

In the second argument to signrawtransactionwithwallet did you pass the list of previous transactions for the inputs you are trying to spend? It is a JSON array so you can decode the previous transaction hex strings to get the required information to this RPC call. It has this format:

...
Arguments:
1. hexstring                        (string, required) The transaction hex string
2. prevtxs                          (json array, optional) A json array of previous dependent transaction outputs
     [
       {                            (json object)
         "txid": "hex",             (string, required) The transaction id
         "vout": n,                 (numeric, required) The output number
         "scriptPubKey": "hex",     (string, required) script key
         "redeemScript": "hex",     (string) (required for P2SH) redeem script
         "witnessScript": "hex",    (string) (required for P2WSH or P2SH-P2WSH) witness script
         "amount": amount,          (numeric or string, required) The amount spent
       },
       ...
     ]


Title: Re: bitcoin-cli cold sign raw transaction
Post by: zoltanb on January 05, 2021, 07:56:43 AM
Yes, I passed it, this is when I received the "Unable to sign input, missing keys".
Probably the problem is with the fact that the address is e bech32 address. Should I try with a legacy address?


Title: Re: bitcoin-cli cold sign raw transaction
Post by: NotATether on January 05, 2021, 10:33:47 AM
Yes, I passed it, this is when I received the "Unable to sign input, missing keys".
Probably the problem is with the fact that the address is e bech32 address. Should I try with a legacy address?

Using a legacy address in the place of bech32 is just going to eliminate the witnessScript part of the prevtxs argument, which I don't think is causing the missing keys error.

Are there and logs in debug.log or bitcoind output showing activity that's happening inside this RPC call? I don't think there are any but it's worth a shot.

It would also be helpful if you decode your transaction hex into JSON and post it here, erasing parts like addresses which you don't want to show if any. I suspect you could be having the same symptoms as the other thread, the vins having an empty ScriptSig.


Title: Re: bitcoin-cli cold sign raw transaction
Post by: coinlatte on January 06, 2021, 05:30:42 PM
Quote
It would also be helpful if you decode your transaction hex into JSON and post it here, erasing parts like addresses which you don't want to show if any. I suspect you could be having the same symptoms as the other thread, the vins having an empty ScriptSig.
More than that: you can run your client with regtest mode and then reproduce it with worthless regtest coins and paste results here. You can use one client as a miner, create some blocks and then use another instance of a regtest client pointed to different directory and different port, then try to sign a transaction from the second client. If both clients are disconnected from each other, it should be enough to reproduce it.