<ol>
<li><p>Technically, the ScriptSig depends on the particular type of transaction output you're trying to claim, but for all standard scripts, it consists of the signature of this transaction and (usually) the public key corresponding to the private key the signature was made with. The public key must be the correct one to claim the transaction output this claims, that is, the one the coins were sent to.</p></li>
<li><p>Bitcoin scripts use opcodes. They're documented in the <a href="https://en.bitcoin.it/wiki/Script#Words" rel="nofollow">wiki</a>.</p></li>
<li><p>That is the Bitcoin address that can claim this output (in raw binary form), assuming the transaction is a <a href="https://en.bitcoin.it/wiki/Transactions#Transfer_to_Bitcoin_address" rel="nofollow">transfer to a Bitcoin address</a>.</p></li>
</ol>

CC BY-SA 3.0
2012-02-08T05:12:28.663Z
David, so if I understand you correctly, this transaction includes the ScriptSig which includes the signature of this transaction.  How can that work?  I can't sign the transaction until it's finished, and the transaction is not finished until it includes its own signature.  Is there a precise description of what exactly gets signed somewhere?
Chris Moore
CC BY-SA 3.0
2012-02-08T05:16:23.070Z
@ChrisMoore You have no choice but to place the signatures in after you generate them, so there's no issue when generating the transaction. When you check the signature of the transaction, you remove the signatures first.
David Schwartz
CC BY-SA 3.0
2012-02-08T08:10:11.000Z
That makes sense.  So is the procedure: create the transaction without signatures, hash the partially complete transaction, sign that hash with each of the private keys needed to spend the inputs and insert those signatures into the partial transaction?  I'm not clear on what it is exactly that gets signed.  Does each input's signature involve all the inputs, or only the input that's having its ScriptSig written at that time?
Chris Moore
CC BY-SA 3.0
2012-02-08T08:13:59.713Z
The signature is of the hash of the entire transaction, with all signatures removed.
David Schwartz
CC BY-SA 3.0
2012-02-08T10:17:43.557Z
I've tried reading the source and there it looks like the public keys are removed from the SigScripts, as well as the signatures.  The comment says "Blank out other inputs' signatures" but the code says "txTmp.vin[i].scriptSig = CScript();".  I guess the comment is slightly wrong.
Chris Moore
CC BY-SA 3.0
2011-09-09T19:38:34.173Z
2011-09-09T19:52:10.463Z
2011-09-09T19:52:10.463Z
David Schwartz
<p>Form the <a href="https://en.bitcoin.it/wiki/Transactions">Bitcoin Wiki - Transactions</a> I see a transaction has the following format.</p>

<pre><code>Input:
Previous tx: f5d8ee39a430901c91a5917b9f2dc19d6d1a0e9cea205b009ca73dd04470b9a6
Index: 0
scriptSig: 304502206e21798a42fae0e854281abd38bacd1aeed3ee3738d9e1446618c4571d10
90db022100e2ac980643b0b82c0e88ffdfec6b64e3e6ba35e7ba5fdd7d5d6cc8d25c6b241501

Output:
Value: 5000000000
scriptPubKey: OP_DUP OP_HASH160 404371705fa9bd789a2fcd52d2c580b65d35549d
OP_EQUALVERIFY OP_CHECKSIG
</code></pre>

<p>The input in this transaction imports 50 BTC from output #0 in transaction f5d8... Then the output sends 50 BTC to a Bitcoin address (expressed here in hexadecimal 4043... instead of the normal base58). When the recipient wants to spend this money, he will reference output #0 of this transaction in an input of his own transaction. </p>

<p>I'm assuming I could use BlockExplorer to find the <code>Previous tx</code> and <code>Index</code>.</p>

<ol>
<li><p>How would I generate the <code>scriptSig</code> ? Is it something that could be done on the command line e.g. openssl.</p></li>
<li><p>The <code>OP_DUP OP_HASH160</code> is that literally placed into the transaction text or is it a pseudonym ?</p></li>
<li><p>The <code>40437...</code> in the scriptPubkey, how would I create that ?</p></li>
</ol>

CC BY-SA 3.0
2012-03-21T23:01:29.053Z
Hmm, I'm also looking for some guide on how to do this and can't seem to find any resources.
ThePiachu
<transactions><script>
How would I hand code a Bitcoin transaction
Ian Purton
# How would I hand code a Bitcoin transaction

(Asked by: username_0 on 2011-09-09)

Form the [Bitcoin Wiki - Transactions](https://en.bitcoin.it/wiki/Transactions) I see a transaction has the following format.

```
Input:
Previous tx: f5d8ee39a430901c91a5917b9f2dc19d6d1a0e9cea205b009ca73dd04470b9a6
Index: 0
scriptSig: 304502206e21798a42fae0e854281abd38bacd1aeed3ee3738d9e1446618c4571d10
90db022100e2ac980643b0b82c0e88ffdfec6b64e3e6ba35e7ba5fdd7d5d6cc8d25c6b241501

Output:
Value: 5000000000
scriptPubKey: OP_DUP OP_HASH160 404371705fa9bd789a2fcd52d2c580b65d35549d
OP_EQUALVERIFY OP_CHECKSIG

```

The input in this transaction imports 50 BTC from output #0 in transaction f5d8... Then the output sends 50 BTC to a Bitcoin address (expressed here in hexadecimal 4043... instead of the normal base58). When the recipient wants to spend this money, he will reference output #0 of this transaction in an input of his own transaction.

I'm assuming I could use BlockExplorer to find the `Previous tx` and `Index`.

1. How would I generate the `scriptSig` ? Is it something that could be done on the command line e.g. openssl.
2. The `OP_DUP OP_HASH160` is that literally placed into the transaction text or is it a pseudonym ?
3. The `40437...` in the scriptPubkey, how would I create that ?

**Tags:** transactions, script

> **Comments:**
> **username_1**: Hmm, I'm also looking for some guide on how to do this and can't seem to find any resources.  

---

## 1 answers

### Answer by username_2 on 2011-09-09. Score: 2

1. Technically, the ScriptSig depends on the particular type of transaction output you're trying to claim, but for all standard scripts, it consists of the signature of this transaction and (usually) the public key corresponding to the private key the signature was made with. The public key must be the correct one to claim the transaction output this claims, that is, the one the coins were sent to.
2. Bitcoin scripts use opcodes. They're documented in the [wiki](https://en.bitcoin.it/wiki/Script#Words).
3. That is the Bitcoin address that can claim this output (in raw binary form), assuming the transaction is a [transfer to a Bitcoin address](https://en.bitcoin.it/wiki/Transactions#Transfer_to_Bitcoin_address).

> **Comments:**
> **username_3**: username_2, so if I understand you correctly, this transaction includes the ScriptSig which includes the signature of this transaction.  How can that work?  I can't sign the transaction until it's finished, and the transaction is not finished until it includes its own signature.  Is there a precise description of what exactly gets signed somewhere?  
> **username_2**: @username_3 You have no choice but to place the signatures in after you generate them, so there's no issue when generating the transaction. When you check the signature of the transaction, you remove the signatures first.  
> **username_3**: That makes sense.  So is the procedure: create the transaction without signatures, hash the partially complete transaction, sign that hash with each of the private keys needed to spend the inputs and insert those signatures into the partial transaction?  I'm not clear on what it is exactly that gets signed.  Does each input's signature involve all the inputs, or only the input that's having its ScriptSig written at that time?  
> **username_2**: The signature is of the hash of the entire transaction, with all signatures removed.  
> **username_3**: I've tried reading the source and there it looks like the public keys are removed from the SigScripts, as well as the signatures.  The comment says "Blank out other inputs' signatures" but the code says "txTmp.vin[i].scriptSig = CScript();".  I guess the comment is slightly wrong.  

---

