Do i need to sign each input in a raw transaction?

1

I've been reading up about raw transactions on bitcoin.org and there are two examples Simple and Complex.

What I can't tell from the information provided is if it necessary to sign each of the inputs separately, or whether you can just sign the entire tx with one.

So two examples:

  1. Input 1 came from address A and input 2 came from address A.
  2. Input 1 came from address B and input 2 came from address C.

For example 1, my assumption is that I could just use

bitcoin-cli signrawtransaction RAW_TX

but for example 2 I would have to use

 bitcoin-cli signrawtransaction RAW_TX [] ["ADDR_B_PRIVATE_KEY"]
 bitcoin-cli signrawtransaction PARTLY_SIGNED_RAW_TX [] ["$ADDR_B_PRIVATE_KEY"]

Ne0

Posted 2017-12-01T11:22:00.327

Reputation: 111

next to the answers below, this is at the tx level itself, if not using a wallet: https://bitcoin.stackexchange.com/questions/41209/how-to-sign-a-transaction-with-multiple-inputs?rq=1

pebwindkraft 2017-12-01T15:09:11.930

Answers

2

Do i need to sign each input in a raw transaction?

Technically, yes. But software like Bitcoin Core Client signs all inputs where the private keys are known. And of course, leave unsigned/untouched all other inputs.

amaclin

Posted 2017-12-01T11:22:00.327

Reputation: 5 763

1

You can just use

bitcoin-cli signrawtransaction RAW_TX

if the private keys of all inputs of that transaction are in your Bitcoin Core (or bitcoind).

MCCCS

Posted 2017-12-01T11:22:00.327

Reputation: 5 827

And what if the keys are not imported (but known anyway)? How should it be added as a argument? a list with each key, all in the same order as the outputs ?Alex 2018-01-04T22:56:16.293

@FeedTheWeb Do this for each key: importprivkey PRIVKEY "" false Don't forget to type false, and.the order doesn't matter. If this doesn't work, do a rescan after adding each key (but probably it won't be needed.) If you have lots of keys, I may write you a little piece of code that reads the PrivKeys from a file and imports them.MCCCS 2018-01-05T04:20:07.557

And if I don't want to import/rescan (because it takes forever), the syntax should be bitcoin-cli signrawtransaction RAW_TX [] ["PRIVKEY1", "PRIVKEY2"] , right?Alex 2018-01-05T11:40:15.237

@FeedTheWeb No, importprivkey PRIVKEY "" false won't rescan, because the last argument is rescan?, false. And you're right, you don't need to importprivkey, your command is correct.MCCCS 2018-01-05T12:35:24.983