4

How do I get to the value in the 'scriptPubKey' part of the transaction ? decoded transaction

The sender knows only the address (1A3XjcuZmcszX2tGoVn1TrMNchuHwdAxZV) so how did he get into 63339ebf4914d964fbc729b0dc4c1a44c4fb8f80 ? I've tried ripemd160(sha256(address)) didn't work . I've tried sha256(sha256(address)) didn't work.

2 Answers 2

6

Addresses are kept in Base58Check format. Here's how you decode it.

  1. Decode the base58 encoding (similar to Base64). You should have 25 bytes.
  2. Check that the 1st byte is 0x00 (the version byte of Bitcoin)
  3. Check that the last 4 bytes are a correct checksum of the rest. This is done (in Python) by:

    sha256(sha256(data[0:21]))[:4] == data[-4:]
    

    (Or, "take the first 4 bytes of a double-SHA256 of the first 21 bytes of the decoded data, then compare to the last 4 bytes of the decoded data.")

  4. Take the middle 20 bytes (data[1:21]) and insert it into the following scriptPubKey.

    OP_DUP OP_HASH160 <x> OP_EQUALVERIFY OP_CHECKSIG
    

Here are some libraries that will do steps 1-3:

3
  • Worked well accept "Check that the last four bytes are a correct checksum" , of what ? Commented Mar 28, 2015 at 21:02
  • @HaddarMacdasi Does the edit make it more clear?
    – Nick ODell
    Commented Mar 28, 2015 at 21:13
  • I'm trying with an online tool. can't seem to work it out. The checksum part. Commented Mar 28, 2015 at 21:18
1

If you are using C# with NBitcoin

var address = new Script("OP_DUP OP_HASH160 ... OP_EQUALVERIFY OP_CHECKSIG").GetDestinationAddress(Network.Main);

It has the nice effect to work with P2SH addresses too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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