<p>A signature is applied to the input being signed by default, so you don't really pick the input.</p>

<p>You have two options:</p>

<p><code>SIGHASH_SINGLE</code> - All inputs are signed, and a single output with the same vout index as your vin index is signed. That is to say, if you have a tx with 5 inputs, out of which your input is the second one, and 4 outputs, all five inputs and the second output will be signed.</p>

<p><code>SIGHASH_SINGLE | SIGHASH_ANYONECANPAY</code> - This will only sign your input and the corresponding output, instead of signing all the inputs. Essentially, in the above example, input 2 and output 2 will be signed.</p>

CC BY-SA 4.0
2018-09-02T14:05:33.013Z
Thanks! In my case, I have 1 input and 5 output, so the SIGHASH_SINGLE will sign the only input, and which output, Vout0 or Vout1 or Vout2? Why?
yrm23
CC BY-SA 4.0
2018-09-02T14:15:52.220Z
From your answer, my understand is that the only new signed vout' index depended on the index of pre vout, is that right. So, if the pre vout's index is 4, the signature will only include the vout 4 for output. Is my understand right?
yrm23
CC BY-SA 4.0
2018-09-02T14:19:43.697Z
It will only sign vout 0, since, you have only one input, which will be at vin0.
Raghav Sood
CC BY-SA 4.0
2018-09-02T14:34:09.137Z
Thanks again. one more question, in your example, why the second output is selected from the four output, not others? my understand is the Sighash code is put at the end of the whole TX message for the whole TX not for a single input. I think maybe  there is something wrong with my understand.
yrm23
CC BY-SA 4.0
2018-09-02T15:22:13.553Z
Each input is signed individually, and the sighash can be different for each input. I wrote [a blog post](https://raghavsood.com/blog/2018/06/10/bitcoin-signature-types-sighash) some time ago on how multi-sighash transactions can be useful, if you are interested in that
Raghav Sood
CC BY-SA 4.0
2018-09-02T03:01:54.647Z
2018-09-02T03:01:54.647Z
Raghav Sood
<p>For my understand, when building a new TX, need to produce a new scriptSig for the TX; and need add a sigHash code at the end of the TX. If the sighash type is SIGHASH_SINGLE, for a TX with multiple input and output, how to specify the right input and output to sign.  </p>

<transactions><input-script><sighash-flags>
How to specify the right input and output to be signed for SIGHASH_SINGLE
yrm23
# How to specify the right input and output to be signed for SIGHASH_SINGLE

(Asked by: username_0 on 2018-09-01)

For my understand, when building a new TX, need to produce a new scriptSig for the TX; and need add a sigHash code at the end of the TX. If the sighash type is SIGHASH\_SINGLE, for a TX with multiple input and output, how to specify the right input and output to sign.

**Tags:** transactions, input-script, sighash-flags


---

## 1 answers

### Answer by username_1 on 2018-09-02. Score: 1

A signature is applied to the input being signed by default, so you don't really pick the input.

You have two options:

`SIGHASH_SINGLE` - All inputs are signed, and a single output with the same vout index as your vin index is signed. That is to say, if you have a tx with 5 inputs, out of which your input is the second one, and 4 outputs, all five inputs and the second output will be signed.

`SIGHASH_SINGLE | SIGHASH_ANYONECANPAY` - This will only sign your input and the corresponding output, instead of signing all the inputs. Essentially, in the above example, input 2 and output 2 will be signed.

> **Comments:**
> **username_0**: Thanks! In my case, I have 1 input and 5 output, so the SIGHASH_SINGLE will sign the only input, and which output, Vout0 or Vout1 or Vout2? Why?  
> **username_0**: From your answer, my understand is that the only new signed vout' index depended on the index of pre vout, is that right. So, if the pre vout's index is 4, the signature will only include the vout 4 for output. Is my understand right?  
> **username_1**: It will only sign vout 0, since, you have only one input, which will be at vin0.  
> **username_0**: Thanks again. one more question, in your example, why the second output is selected from the four output, not others? my understand is the Sighash code is put at the end of the whole TX message for the whole TX not for a single input. I think maybe  there is something wrong with my understand.  
> **username_1**: Each input is signed individually, and the sighash can be different for each input. I wrote [a blog post](https://username_1.com/blog/2018/06/10/bitcoin-signature-types-sighash) some time ago on how multi-sighash transactions can be useful, if you are interested in that  

---

