<p>Simply put, you don't. The address is a hash of the public key with a checksum and a prefix (1). The reason the addresses are not just public keys is unknown, you would have to ask satoshi that, however it is likely make them shorter. BTC does have P2PK but it is not commonly used as the public key is much longer than an address. Hope this helps!</p>

CC BY-SA 4.0
2020-04-08T09:23:57.700Z
2020-04-08T09:23:57.700Z
Leah Cornelius
<p>Perhaps you're confused by the phrasing &quot;the wallet&quot;, as it's only the receiver's wallet who needs to know the public key, and he has it, because he created the address in the first place.</p>
<p>In what follows, I'm going to assume a standard 1... address (pay to pubkey hash). That's not the only type of address, but similar ressonings apply to every type of addresses.</p>
<p>In the normal workflow, there are two wallets involved. Let's call them Suzy (the sender) and Rudy (the receiver).</p>
<ul>
<li>Rudy generates a private key x.</li>
<li>Rudy computes the public key corresonding to x, called P.</li>
<li>Rudy computes the address A corresponding to P by hashing it.</li>
<li>Rudy sends A to Suzy (by sending it in person, or putting it on a website, or showing it as a QR code, or ...).</li>
<li>Suzy constructs a transaction that contains an output addressed to A. Suzy has no clue what public key A corresponds to, but also doesn't care. This address really encodes &quot;require a public key and a signature valid for that key, and the hash of the public key needs to be A&quot;.</li>
<li>Suzy broadcasts the transaction on the network, where it will be picked up by miners who put it in a block, finalizing the transfer.</li>
<li>Now when Rudy wants to spend the coins he received from Suzy, he needs to satisfy the condition that Suzy put in the transaction. This requires the public key P (as that's the only known public key whose hash is A), and a signature created using private key x (which is the only private key that can construct signatures that are valid for P). Thankfully, Rudy has both x and P, because he was the one who created them.</li>
</ul>

CC BY-SA 4.0
2019-08-04T10:46:49.990Z
Thank you, I always thought transactions where P2PK.
Ariel Hurdle
CC BY-SA 4.0
2020-01-08T01:19:11.960Z
Just to comment that the pubkey hash is not the address. The address is the double hash of the pubkey [ i.e. pubkeyhash=sha256(pubkey), address=sha256(pubkeyhash)=sha256(sha256(pubkey))=sha256d(pubkey) ]
José Crespo Barrios
CC BY-SA 4.0
2020-01-08T01:24:05.897Z
@Jose In common terminology, "pubkey hash" refers to SHA256+RIPEMD160
Pieter Wuille
CC BY-SA 4.0
2020-02-01T09:49:02.977Z
I had the same question about how wallets get the pub key hash from an address. Here's a nice diagram that illustrates the ability to go from a bitcoin address to and from a public key hash - https://learnmeabitcoin.com/guide/p2pkh
dodgy_coder
CC BY-SA 4.0
2024-12-12T16:43:21.070Z
This answer could perhaps explicitly mention that the receiver defines what the output should look like and the sender should never make guesses at what else might be acceptable but either follow the receivers instructions or follow-up.
Murch
CC BY-SA 4.0
2019-08-03T18:37:18.540Z
2023-04-05T00:40:19.317Z
2023-04-05T00:40:19.317Z
Pieter Wuille
<p>There are different kinds of outputs a transaction can pay to.
For simplicity I'll explain it with a <a href="https://en.bitcoin.it/wiki/Transaction#Pay-to-PubkeyHash" rel="nofollow noreferrer">Pay-to-PubkeyHash</a> (P2PKH) output as an example. I think this is what your question is based on.</p>

<p>With a P2PKH output you are right. An address is just an encoded and hashed public key with a prefix. You can remove the prefix and reverse the encoding, but you can't find the preimage to the hash (in our case the public key).</p>

<p>But you don't need to. As the name <code>Pay-to-PubkeyHash</code> suggests, you only pay to the hash of the public key in your transaction. The receiver can derive the public key, as long as he has corresponding the private key, if he needs to.</p>

CC BY-SA 4.0
2019-08-03T13:23:41.070Z
thanks, so on the blockchain transaction records dont use the public key of the reciver but the hash of the public key? and then i presume when getting your balance you scan the blockchsin with your address rather than yoir public key?
Ariel Hurdle
CC BY-SA 4.0
2019-08-03T13:31:27.380Z
There are different kinds of transactions. For P2PKH only the public key hash is included when paying to an address (someone spending a P2PKH output reveals the public key though). A wallet knows the private keys, calculates the public keys and their hashes and 'scans' for them.
0xb10c
CC BY-SA 4.0
2019-08-03T13:35:40.653Z
@oxb10c ok so for P2PKH the wallet doesnt need the public key, but what about P2PK transactions? how does the wallet send those?
Ariel Hurdle
CC BY-SA 4.0
2019-08-03T14:06:32.960Z
For P2PK you don't hash the public key in the address, just encode and add a prefix.
0xb10c
CC BY-SA 4.0
2019-08-03T14:16:57.520Z
I see, so the receiver would generate his address like this ```Publickey --> encode (eg AES?) --> add prefix = address``` and then the sender reverses that proccess?
Ariel Hurdle
CC BY-SA 4.0
2019-08-03T18:46:09.740Z
There is no encryption anywhere in the Bitcoin protocol. For P2PK the sender puts the public key directly in the crediting transaction, and to spend it, the receiver provides a signature. But there are no addresses for P2PK outputs, so the sender needs some other way of figuring out the receiver's full public key. Such transactions are very uncommon now.
Pieter Wuille
CC BY-SA 4.0
2019-08-03T13:18:46.640Z
2020-02-20T15:00:18.267Z
2020-02-20T15:00:18.267Z
0xb10c
<blockquote>
  <p>I was under the impression that addresses are just a encoded</p>
</blockquote>

<p>Yes, addresses are encoded (base58 or base32) to help human readability. They include a checksum to ensure protection against errors in address transcription and entry. A bitcoin address can represent the owner of a private/ public key pair, or it can represent any other script that can be represented through P2SH or P2WSH. </p>

<blockquote>
  <p>But if the public key is hashed, how does the wallet get the public key from the address to create a transaction?</p>
</blockquote>

<p>To create a transaction that spends your bitcoins, you need access to the private key. That is because almost all of the transactions need to include the signature of the private key you hold in order to spend the funds that were locked.</p>

<p>However, you can have a watch-only wallet in case you are apprehensive of using private keys on a network connected device. A watch-only wallet allows you to watch what happens to those cold storage bitcoins without exposing the private keys to the online world. This includes importing your master public key at the account level that helps you create different addresses for that account. With the master public key at the account level, you can create receiving/change addresses as you have access to the public keys that will be used to create those addresses. The software just hashes the public keys and encode them in the way you like (P2WPKH or P2PKH). </p>

CC BY-SA 4.0
2019-08-04T16:43:18.300Z
@ArielHurdle You cannot derive public key from the address. Addresses are mostly `hash160` of the public key and hashes are one way mathematical functions. If you want to create a P2PK transaction, you would need to ask the payee directly for the public key.
Ugam Kamat
CC BY-SA 4.0
2019-08-03T18:33:29.737Z
2019-08-03T18:33:29.737Z
Ugam Kamat
<p>I was under the impression that addresses are just an encoded, hashed public keys with a prefix and that only the public key is used on the blockchain (not the address) for transactions.
But if the public key is hashed, how does the wallet get the public key from the address to create a transaction?</p>

<p>I did some research which confirmed my doubts <a href="https://bitcoin.stackexchange.com/questions/11604/is-it-possible-to-get-the-public-key-of-a-bitcoin-address-i-do-not-have-the-priv">that this is not possible</a>. So I was wondering, how does the wallet create a transaction if it doesn't have the public key?</p>

<p>EDIT:
I mean how does someone trying to send 10 BTC get the public key of the receiver for pay to public key from the receivers to address. I fully understand the cryptographic element of private &amp; public keypairs and how bitcoin is spent just not how the public key of the receiver is derived from the address. What I have seen is that (most commonly) transactions are pay to public key hash (P2PKH) rather than what I originally thought which was all txns are pay to public key (P2PK).</p>

<wallet><address><public-key>
How does a wallet get the public key from an address?
Ariel Hurdle
# How does a wallet get the public key from an address?

(Asked by: username_0 on 2019-08-03)

I was under the impression that addresses are just an encoded, hashed public keys with a prefix and that only the public key is used on the blockchain (not the address) for transactions.
But if the public key is hashed, how does the wallet get the public key from the address to create a transaction?

I did some research which confirmed my doubts [that this is not possible](https://bitcoin.stackexchange.com/questions/11604/is-it-possible-to-get-the-public-key-of-a-bitcoin-address-i-do-not-have-the-priv). So I was wondering, how does the wallet create a transaction if it doesn't have the public key?

EDIT:
I mean how does someone trying to send 10 BTC get the public key of the receiver for pay to public key from the receivers to address. I fully understand the cryptographic element of private & public keypairs and how bitcoin is spent just not how the public key of the receiver is derived from the address. What I have seen is that (most commonly) transactions are pay to public key hash (P2PKH) rather than what I originally thought which was all txns are pay to public key (P2PK).

**Tags:** wallet, address, public-key


---

## 4 answers

### Answer by username_1 on 2020-04-08. Score: 1 | Accepted answer

Simply put, you don't. The address is a hash of the public key with a checksum and a prefix (1). The reason the addresses are not just public keys is unknown, you would have to ask satoshi that, however it is likely make them shorter. BTC does have P2PK but it is not commonly used as the public key is much longer than an address. Hope this helps!


---

### Answer by username_2 on 2019-08-03. Score: 10

Perhaps you're confused by the phrasing "the wallet", as it's only the receiver's wallet who needs to know the public key, and he has it, because he created the address in the first place.

In what follows, I'm going to assume a standard 1... address (pay to pubkey hash). That's not the only type of address, but similar ressonings apply to every type of addresses.

In the normal workflow, there are two wallets involved. Let's call them Suzy (the sender) and Rudy (the receiver).

* Rudy generates a private key x.
* Rudy computes the public key corresonding to x, called P.
* Rudy computes the address A corresponding to P by hashing it.
* Rudy sends A to Suzy (by sending it in person, or putting it on a website, or showing it as a QR code, or ...).
* Suzy constructs a transaction that contains an output addressed to A. Suzy has no clue what public key A corresponds to, but also doesn't care. This address really encodes "require a public key and a signature valid for that key, and the hash of the public key needs to be A".
* Suzy broadcasts the transaction on the network, where it will be picked up by miners who put it in a block, finalizing the transfer.
* Now when Rudy wants to spend the coins he received from Suzy, he needs to satisfy the condition that Suzy put in the transaction. This requires the public key P (as that's the only known public key whose hash is A), and a signature created using private key x (which is the only private key that can construct signatures that are valid for P). Thankfully, Rudy has both x and P, because he was the one who created them.

> **Comments:**
> **username_0**: Thank you, I always thought transactions where P2PK.  
> **username_3**: Just to comment that the pubkey hash is not the address. The address is the double hash of the pubkey [ i.e. pubkeyhash=sha256(pubkey), address=sha256(pubkeyhash)=sha256(sha256(pubkey))=sha256d(pubkey) ]  
> **username_2**: @Jose In common terminology, "pubkey hash" refers to SHA256+RIPEMD160  
> **username_4**: I had the same question about how wallets get the pub key hash from an address. Here's a nice diagram that illustrates the ability to go from a bitcoin address to and from a public key hash - https://learnmeabitcoin.com/guide/p2pkh  
> **username_5**: This answer could perhaps explicitly mention that the receiver defines what the output should look like and the sender should never make guesses at what else might be acceptable but either follow the receivers instructions or follow-up.  

---

### Answer by username_6 on 2019-08-03. Score: 1

There are different kinds of outputs a transaction can pay to.
For simplicity I'll explain it with a [Pay-to-PubkeyHash](https://en.bitcoin.it/wiki/Transaction#Pay-to-PubkeyHash) (P2PKH) output as an example. I think this is what your question is based on.

With a P2PKH output you are right. An address is just an encoded and hashed public key with a prefix. You can remove the prefix and reverse the encoding, but you can't find the preimage to the hash (in our case the public key).

But you don't need to. As the name `Pay-to-PubkeyHash` suggests, you only pay to the hash of the public key in your transaction. The receiver can derive the public key, as long as he has corresponding the private key, if he needs to.

> **Comments:**
> **username_0**: thanks, so on the blockchain transaction records dont use the public key of the reciver but the hash of the public key? and then i presume when getting your balance you scan the blockchsin with your address rather than yoir public key?  
> **username_6**: There are different kinds of transactions. For P2PKH only the public key hash is included when paying to an address (someone spending a P2PKH output reveals the public key though). A wallet knows the private keys, calculates the public keys and their hashes and 'scans' for them.  
> **username_0**: @oxb10c ok so for P2PKH the wallet doesnt need the public key, but what about P2PK transactions? how does the wallet send those?  
> **username_6**: For P2PK you don't hash the public key in the address, just encode and add a prefix.  
> **username_0**: I see, so the receiver would generate his address like this ```Publickey --> encode (eg AES?) --> add prefix = address``` and then the sender reverses that proccess?  
> **username_2**: There is no encryption anywhere in the Bitcoin protocol. For P2PK the sender puts the public key directly in the crediting transaction, and to spend it, the receiver provides a signature. But there are no addresses for P2PK outputs, so the sender needs some other way of figuring out the receiver's full public key. Such transactions are very uncommon now.  

---

### Answer by username_7 on 2019-08-03. Score: 1

> I was under the impression that addresses are just a encoded

Yes, addresses are encoded (base58 or base32) to help human readability. They include a checksum to ensure protection against errors in address transcription and entry. A bitcoin address can represent the owner of a private/ public key pair, or it can represent any other script that can be represented through P2SH or P2WSH.

> But if the public key is hashed, how does the wallet get the public key from the address to create a transaction?

To create a transaction that spends your bitcoins, you need access to the private key. That is because almost all of the transactions need to include the signature of the private key you hold in order to spend the funds that were locked.

However, you can have a watch-only wallet in case you are apprehensive of using private keys on a network connected device. A watch-only wallet allows you to watch what happens to those cold storage bitcoins without exposing the private keys to the online world. This includes importing your master public key at the account level that helps you create different addresses for that account. With the master public key at the account level, you can create receiving/change addresses as you have access to the public keys that will be used to create those addresses. The software just hashes the public keys and encode them in the way you like (P2WPKH or P2PKH).

> **Comments:**
> **username_7**: @username_0 You cannot derive public key from the address. Addresses are mostly `hash160` of the public key and hashes are one way mathematical functions. If you want to create a P2PK transaction, you would need to ask the payee directly for the public key.  

---

