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
  • 111
  • 3
  • 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 Dec 01 '17 at 15:09

2 Answers2

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
  • 6,760
  • 1
  • 21
  • 32
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
  • 10,206
  • 5
  • 27
  • 56
  • 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 Jan 04 '18 at 22:56
  • @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 Jan 05 '18 at 04:20
  • 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 Jan 05 '18 at 11:40
  • @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 Jan 05 '18 at 12:35