Bitcoin script example

7

2

Is there some good example on how to process a basic tx's scriptsig and get the recipient's address from the raw transaction?

ThePiachu

Posted 2011-12-15T21:50:12.490

Reputation: 41 594

Answers

6

In the output there is a field "scriptPubKey" that for a standard transaction looks like this:

OP_DUP OP_HASH160 62e907b15cbf27d5425399ebf6f0fb50ebb88f18 OP_EQUALVERIFY OP_CHECKSIG

The hex number is what you get the address from; this is the result of step #3 in https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses. To get the address continue the process in that example. (Though, arguably the hardest part is calculating Base58Check, for which an example is not given.)

Also relevant is https://en.bitcoin.it/wiki/Script#Standard_Transaction_to_Bitcoin_address.

Meni Rosenfeld

Posted 2011-12-15T21:50:12.490

Reputation: 18 542

2Hmm, nothing like using the wiki entry I wrote against me ;) (the first one). And the base 58 is not much of a problem, already programmed that awhile ago.ThePiachu 2011-12-16T07:28:20.560

Has the Script been changed since the Genesis Block? I am having some problems figuring out how to process this scriptPubKey from that block: 4104678AFDB0FE5548271967F1A67130B7105CD6A828E03909A67962E0EA1F61DEB649F6BC3F4CEF38C4F35504E51EC112DE5C384DF7BA0B8D578A4C702B6BF11D5FACThePiachu 2011-12-17T01:37:16.590

This transaction uses the https://en.bitcoin.it/wiki/Script#Standard_Generation_.2F_transaction_to_IP_address type. In it you have the public key itself before any hashing (step #1). The public key in the genesis block is 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f, I'm not sure where you got this value from.

Meni Rosenfeld 2011-12-17T16:37:59.870

It's the same public key, but with opcodes added on both sides - push 0x41 bytes on the left and checksig on the right. So it is a raw scriptpubkey dump from https://en.bitcoin.it/wiki/Genesis_block

ThePiachu 2011-12-17T22:49:50.187