1

It looks to me like each input to a bitcoin transaction has an index that specifies only one output from the input its spending. Is there a way to specify more than one output index, or do you have to create a second input line that contains the same input ID with a different index? It seems like that second way is wasteful of blockchain space - I would have thought there would be a way to simply specify multiple indexes. Is there a way to do that?

2

It looks to me like each input to a bitcoin transaction has an index that specifies only one output from the input its spending.

That is correct.

Is there a way to specify more than one output index, or do you have to create a second input line that contains the same input ID with a different index?

You have to add an extra input, which repeats the txid.

It seems like that second way is wasteful of blockchain space - I would have thought there would be a way to simply specify multiple indexes.

It is wasteful, but only slightly. In your hypothetical system, you still need a signature/scriptSig/witness for each of the coins being spent (unless you also want to incentivize key reuse), which are generally larger than a repetition of a txid.

Is there a way to do that?

No.

0

Can you specify more than one output index in a transaction's input?

yes. Transactions consists of structures, including a list of inputs (V_IN) and a list of outputs (V_OUT). You can have several V_INs, and several V_OUTs. A similar question is here.

Is there a way to specify more than one output, or do you have to create a second input line that contains the same input ID with a different index?

Not sure what is meant by lines... In a tx the data is structured, and an output is defined by the list of outputs (V_OUT, link to the wiki). It is possible to create a transaction with one input, and have many outputs. One can create these transactions manually, or also use the bitcoin core client, with the API call "createrawtransaction". The parameters are: [{"txid":txid,"vout":n},...] {address:amount,...} - one can provide several addresses with the amounts. For example faucets sending mini amounts of BTC assemble such transactions, to save on the fees. And so one transaction may have a single input, and 100s of outputs.

=== update 18 April 2018, based on comments below ===

I think I see what is meant. Assuming, a given tx has two outputs, with 4 values of 0.25 BTC. All shall be spent in a single transaction, with a single tx_in structure, along this idea:

...
  tx_in[0] OutPoint hash   (previous tx hash)
   tx_in[0] OutPoint_index[0] (previous tx' outpoint index --> 0.25 BTC)
   tx_in[0] OutPoint_index[1] 
   tx_in[0] OutPoint_index[2] 
   tx_in[0] OutPoint_index[3] 
  tx_in[0] Script Length   (length for the following signature script)
  tx_in[0] Script Sig      (the signature script)
  tx_in[0] Sequence        (usually set to FFFFFFFF)
...

This would make the transaction short, and reduce amount of space used in the blockchain and redu ce fees. As Pieter replied already, it is not possible. The current definition of the transaction structure does not allow for such a variation. The specification defines a single Outpoint Index per tx_in. So to use several outputs from a previous tx, one would have to create equivalent amount of tx_in structures, each referencing a single Output Index (and tx hash, and adding script length, sigcscript and sequence).

  • What I meant is: is there a way to specify two output indexes for a given output? I know you can add multiple outputs, but lets say you want to use all the ouputs from a given transaction. Could you, in that case, say something to the effect of "use output index 1, 2, 3, 4, and 5 from transaction X" or do you have to say "use output index 1 from transaction X, and use output index 2 from transaction X, ..." etc? – B T Apr 17 '18 at 22:46
  • I believe OP is asking about a way to spend multiple outputs from the same txid in a way that is more efficient than creating an extra input and repeating the txid. – Pieter Wuille Apr 17 '18 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.