I'm trying to sign a coinbase transaction. I know I need to use 76 A9 14 (HASH160) 88 AC but I don't understand how to create the HASH160 (20 byte) from a bitcoin address.

4 Answers 4


Check the Wiki. I think what you are looking for is point 3:

How to create Bitcoin Address

0 - Having a private ECDSA key


1 - Take the corresponding public key generated with it (65 bytes, 1 byte 0x04, 32 bytes corresponding to X coordinate, 32 bytes corresponding to Y coordinate)


2 - Perform SHA-256 hashing on the public key


3 - Perform RIPEMD-160 hashing on the result of SHA-256


4 - Add version byte in front of RIPEMD-160 hash (0x00 for Main Network)


5 - Perform SHA-256 hash on the extended RIPEMD-160 result


6 - Perform SHA-256 hash on the result of the previous SHA-256 hash


7 - Take the first 4 bytes of the second SHA-256 hash. This is the address checksum


8 - Add the 4 checksum bytes from point 7 at the end of extended RIPEMD-160 hash from point 4. This is the 25-byte binary Bitcoin Address.


9 - Convert the result from a byte string into a base58 string using Base58Check encoding. This is the most commonly used Bitcoin Address format


You can check your calculations against my testing suite.

  • 1
    Thanks! Unfortunately, point 0 is where I get lost... Does calculating the hash require access to the private key? Can I sign a coinbase transaction using a bitcoin address bypassing the need to calculate the HASH160?
    – user789235
    Oct 9, 2012 at 16:44
  • @user789235 If you want to SPEND the transaction, you need a private key. If you want to specify the recipient of the transaction, you only need to put the address in and some ops. Read here for more info en.bitcoin.it/wiki/Script#Scripts
    – ThePiachu
    Oct 9, 2012 at 18:19
  • Thank you. I'm pretty sure I get it. So, I now want to create a signature of a testnet coinbase transaction. Is there an easier way to get the hash than starting with generating a public/private key pair from scratch?
    – user789235
    Oct 9, 2012 at 23:38
  • @user789235 If you just want to create a coinbase transaction that credits a given address their coins, you just specify the public key or address in the output script. If you want to create a transaction that spends the coinbase input, I have no idea how to do that.
    – ThePiachu
    Oct 10, 2012 at 10:31
  • Could you incorporate part of the info from the wiki in your answer so that the answer is not dependant on "point 3" on the wiki staying the same. Thanks!
    – D.H.
    Oct 10, 2012 at 20:07

This wiki page is probably more helpful. It describes how the bitcoin address is created from the 160 bit hash. You need to run those steps backwards to get back to the 160 bit hash.

For example, if your address is 1HgiEYL6fsKrfh8wuMhAGfvSc6PY5ZXJdv, you first count and remove the 1's from the start. There's only one '1' in most addresses. Remember this for later.

With the rest of the address, use this page to convert each character into its base58 value: 'H' -> 16, 'g' -> 39, 'i' -> 41, ..., 'v' -> 53 etc. So you have a list of values: [16, 39, 41, ..., 53].

Then combine all these values into a single large number:

(([...](((16) * 58 + 39) * 58 + 41) ...) * 58 + 53) 

Convert the single large number into a sequence of bytes, prepend the same number of 00 bytes as the number of '1's you initially removed from the address, remove the last 4 bytes (that's the checksum), remove the first zero byte (that's the version byte), and there's your 160 bit hash.

  • Perfect! I'll start the calculation. As a lazy mathematician's way of getting what I'm looking for, I came up with this approach. I'm not sure it's valid, but I send 20btc on testnet to the address for which I wanted a HASH160. That transaction is here I think I can use the hash from this transaction. But I'll do the math to confirm....
    – user789235
    Oct 10, 2012 at 17:14
  • I don't think the testnet client will accept a regular bitcoin address as being valid. Maybe I've misunderstood what you did. Oct 11, 2012 at 3:27

For regular addresses you can use the addresstohash tool in blockexplorer.

For testnet addresses you can open https://blockexplorer.com/testnet/address/the address you want and read the Hash160 field. This works for addresses which aren't in the block chain too.

  • Thanks. This was the easy answer I need for my one off test!
    – user789235
    Oct 25, 2012 at 22:46

You can use Casascius address utility to do various manipulations with keys, hashes and addresses.

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