<p>Both P2SH and P2PKH use HASH_160. That's what the <code>h</code> stands for in them.</p>

<p>Each HASH_160 is valid in both addresses. As to which address you need to send your BTC to depends on if you are using a redeem script or a public key to spend it.</p>

<p>If you send it to an address starting with 1, your output is encoded as <code>OP_DUP OP_HASH160 &lt;PubkeyHash&gt; OP_EQUALVERIFY OP_CHECKSIG</code>. To spend this, you require a private key that leads to the public key to which the hash belongs, and sign the tx using that.</p>

<p>If you send it to an address starting with 3, your output is encoded as <code>OP_HASH160 &lt;RedeemScriptHash&gt; OP_EQUAL</code>. In this case, to spend the output, you need to provide a redeem script for which the HASH_160 equals the one used in the address (along with any information that the redeem script might use, such as the signatures for a multisig address, or witness for a segwit address).</p>

<p>Due to this, each HASH160 can effectively be used to generate two addresses. Blockchain.info defaults to showing the 1-address. </p>

<p>DO NOT send any coins to the 1-address if your original address was a 3-address, and vice-versa. You will not be able to recover them.</p>

CC BY-SA 4.0
2018-06-04T11:09:57.180Z
thank you raghav! and why is hash160 useful then?
Alan Deep
CC BY-SA 4.0
2018-06-04T10:20:28.670Z
2018-06-05T00:11:12.263Z
2018-06-05T00:11:12.263Z
Raghav Sood
<blockquote>
  <p>1) is it possible to get the real address (e.g :
  1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1 or
  3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1) from the hash160 address
  (dd9c56410b2e734e551fc34331a056b70e939c98)?</p>
</blockquote>

<p>Yes. It is possible and very easy</p>

<pre><code>const QString MyKey20::toString ( ) const
{
  quint8 tmp1 [21];
  tmp1 [0] = NET_BYTE;
  memcpy ( tmp1 + 1, constData ( ), 20 );
  const MyKey32 key ( tmp1, 21 );
  quint8 tmp2 [25];
  memcpy ( tmp2, tmp1, sizeof ( tmp1 ) );
  memcpy ( tmp2 + 21, key.constData ( ), 4 );
  char addr [40];
  memset ( addr, 0, sizeof ( addr ) );
  BASE58::encodeBase58 ( tmp2, sizeof ( tmp2 ), addr, sizeof ( addr ) - 1 );
  return QString ( addr );
}

const QString MyKey20::toStringP2SH ( ) const
{
  quint8 tmp1 [21];
  tmp1 [0] = P2SH_BYTE;
  memcpy ( tmp1 + 1, constData ( ), 20 );
  const MyKey32 key ( tmp1, 21 );
  quint8 tmp2 [25];
  memcpy ( tmp2, tmp1, sizeof ( tmp1 ) );
  memcpy ( tmp2 + 21, key.constData ( ), 4 );
  char addr [40];
  memset ( addr, 0, sizeof ( addr ) );
  BASE58::encodeBase58 ( tmp2, sizeof ( tmp2 ), addr, sizeof ( addr ) - 1 );
  return QString ( addr );
}
</code></pre>

<blockquote>
  <p>2) why is blockchain.info showing me the the address of the hash160
  (dd9c56410b2e734e551fc34331a056b70e939c98) is
  1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1 and not
  3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1?</p>
</blockquote>

<p>Because blockchain.info programmers haven't implemented this kind of search request. (In fact it was available several years ago, but later they throw it)</p>

CC BY-SA 4.0
2018-06-04T10:20:30.807Z
thank you for your answer however, i don't get it. if i give my friend the hash160 address, the bitcoin will be sent to which address?
Alan Deep
CC BY-SA 4.0
2018-06-04T10:31:55.793Z
you should not give 160bit hash because no client would accept it as valid bitcoin address
amaclin
CC BY-SA 4.0
2018-06-04T10:15:34.707Z
2018-06-04T10:15:34.707Z
amaclin
<p>I am a bit confused here. 
I know that a public address is generated from the private key which you should keep secret, or else, anyone who has it will be able to spend the coins "in that address".</p>

<p>However, when i was checking this link:
<a href="https://blockchain.info/address/dd9c56410b2e734e551fc34331a056b70e939c98" rel="nofollow noreferrer">https://blockchain.info/address/dd9c56410b2e734e551fc34331a056b70e939c98</a>
containing the hash160 address, blockchain.info showed me that the address from which this hash160 was made is the following: <code>1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1</code>
However, if i navigate to this link: 
<a href="https://blockchain.info/address/3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1" rel="nofollow noreferrer">https://blockchain.info/address/3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1</a>
blockchain.info will show me that the hash160 generated from the address : <code>3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1</code> is the same as the one generated from <code>1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1</code>. 
I know that hashing is not a one to one function, it 'is' a many-to-one function but in this case,
My sub-questions are the following:</p>

<p>1) is it possible to get the real address (e.g : 1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1 or 3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1) from the hash160 address (dd9c56410b2e734e551fc34331a056b70e939c98)?</p>

<p>2) why is blockchain.info showing me the the address of the hash160 (dd9c56410b2e734e551fc34331a056b70e939c98) is <code>1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1</code> and <strong>not</strong> <code>3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1</code>?</p>

CC BY-SA 4.0
2018-06-04T10:19:02.457Z
To generate an address from a hash160 you need two inputs. The hash and the version byte. Version byte 0x00 corresponds to a P2PKH address (starting with 1) and version byte 0x05 to a P2SH addres (starting with 3)
Mike D
<bitcoin-core><bitcoin-core-development>
Should i send bitcoins to hash160 or normal address
Alan Deep
# Should i send bitcoins to hash160 or normal address

(Asked by: username_0 on 2018-06-04)

I am a bit confused here.
I know that a public address is generated from the private key which you should keep secret, or else, anyone who has it will be able to spend the coins "in that address".

However, when i was checking this link:
<https://blockchain.info/address/dd9c56410b2e734e551fc34331a056b70e939c98>
containing the hash160 address, blockchain.info showed me that the address from which this hash160 was made is the following: `1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1`
However, if i navigate to this link:
<https://blockchain.info/address/3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1>
blockchain.info will show me that the hash160 generated from the address : `3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1` is the same as the one generated from `1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1`.
I know that hashing is not a one to one function, it 'is' a many-to-one function but in this case,
My sub-questions are the following:

1) is it possible to get the real address (e.g : 1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1 or 3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1) from the hash160 address (dd9c56410b2e734e551fc34331a056b70e939c98)?

2) why is blockchain.info showing me the the address of the hash160 (dd9c56410b2e734e551fc34331a056b70e939c98) is `1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1` and **not** `3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1`?

**Tags:** bitcoin-core, bitcoin-core-development

> **Comments:**
> **username_1**: To generate an address from a hash160 you need two inputs. The hash and the version byte. Version byte 0x00 corresponds to a P2PKH address (starting with 1) and version byte 0x05 to a P2SH addres (starting with 3)  

---

## 2 answers

### Answer by username_2 on 2018-06-04. Score: 1

Both P2SH and P2PKH use HASH\_160. That's what the `h` stands for in them.

Each HASH\_160 is valid in both addresses. As to which address you need to send your BTC to depends on if you are using a redeem script or a public key to spend it.

If you send it to an address starting with 1, your output is encoded as `OP_DUP OP_HASH160 <PubkeyHash> OP_EQUALVERIFY OP_CHECKSIG`. To spend this, you require a private key that leads to the public key to which the hash belongs, and sign the tx using that.

If you send it to an address starting with 3, your output is encoded as `OP_HASH160 <RedeemScriptHash> OP_EQUAL`. In this case, to spend the output, you need to provide a redeem script for which the HASH\_160 equals the one used in the address (along with any information that the redeem script might use, such as the signatures for a multisig address, or witness for a segwit address).

Due to this, each HASH160 can effectively be used to generate two addresses. Blockchain.info defaults to showing the 1-address.

DO NOT send any coins to the 1-address if your original address was a 3-address, and vice-versa. You will not be able to recover them.

> **Comments:**
> **username_0**: thank you username_2! and why is hash160 useful then?  

---

### Answer by username_3 on 2018-06-04. Score: 0

> 1) is it possible to get the real address (e.g :
> 1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1 or
> 3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1) from the hash160 address
> (dd9c56410b2e734e551fc34331a056b70e939c98)?

Yes. It is possible and very easy

```
const QString MyKey20::toString ( ) const
{
  quint8 tmp1 [21];
  tmp1 [0] = NET_BYTE;
  memcpy ( tmp1 + 1, constData ( ), 20 );
  const MyKey32 key ( tmp1, 21 );
  quint8 tmp2 [25];
  memcpy ( tmp2, tmp1, sizeof ( tmp1 ) );
  memcpy ( tmp2 + 21, key.constData ( ), 4 );
  char addr [40];
  memset ( addr, 0, sizeof ( addr ) );
  BASE58::encodeBase58 ( tmp2, sizeof ( tmp2 ), addr, sizeof ( addr ) - 1 );
  return QString ( addr );
}

const QString MyKey20::toStringP2SH ( ) const
{
  quint8 tmp1 [21];
  tmp1 [0] = P2SH_BYTE;
  memcpy ( tmp1 + 1, constData ( ), 20 );
  const MyKey32 key ( tmp1, 21 );
  quint8 tmp2 [25];
  memcpy ( tmp2, tmp1, sizeof ( tmp1 ) );
  memcpy ( tmp2 + 21, key.constData ( ), 4 );
  char addr [40];
  memset ( addr, 0, sizeof ( addr ) );
  BASE58::encodeBase58 ( tmp2, sizeof ( tmp2 ), addr, sizeof ( addr ) - 1 );
  return QString ( addr );
}

```

> 2) why is blockchain.info showing me the the address of the hash160
> (dd9c56410b2e734e551fc34331a056b70e939c98) is
> 1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1 and not
> 3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1?

Because blockchain.info programmers haven't implemented this kind of search request. (In fact it was available several years ago, but later they throw it)

> **Comments:**
> **username_0**: thank you for your answer however, i don't get it. if i give my friend the hash160 address, the bitcoin will be sent to which address?  
> **username_3**: you should not give 160bit hash because no client would accept it as valid bitcoin address  

---

