9

Form the Bitcoin 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 ?

  • Hmm, I'm also looking for some guide on how to do this and can't seem to find any resources. – ThePiachu Mar 21 '12 at 23:01
  • bitcoin.stackexchange.com/questions/3374/… Includes a pretty complete description of what data from the transaction gets signed and how to do it. – user14628 Mar 19 '14 at 3:57
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.

  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.

  • 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 Feb 8 '12 at 5:12
  • 1
    @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 Feb 8 '12 at 5:16
  • 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 Feb 8 '12 at 8:10
  • The signature is of the hash of the entire transaction, with all signatures removed. – David Schwartz Feb 8 '12 at 8:13
  • 1
    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 Feb 8 '12 at 10:17

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.