<p>There are currently 3 types of addresses defined, and each directly encodes a specific scriptPubKey.</p>
<ul>
<li><code>1...</code> addresses. These are P2PKH addresses. To construct their scriptPubKey, use <a href="https://en.bitcoin.it/wiki/Base58Check_encoding" rel="nofollow noreferrer">Base58Check</a> decoding, verify the first byte of the result is 0, and then construct the script <code>OP_DUP OP_HASH160 &lt;byte 1-21 of the Base58Check decode&gt; OP_EQUALVERIFY OP_CHECKSIG</code>.</li>
<li><code>3...</code> addresses. These are P2SH addresses. To construct their scriptPubKey, use Base58Check decoding, verify the first byte of the result is 5, and then construct the script <code>OP_HASH160 &lt;byte 1-21 of the Base58Check decode&gt; OP_EQUAL</code>.</li>
<li><code>bc1...</code> addresses. These are native segwit addresses. To construct their scriptPubKey, follow the procedure documented in BIP173 and BIP350.</li>
</ul>
<p>The prefixes characters/bytes are different for other networks, such as the Bitcoin testnet.</p>
<p>Ideally, you don't need to reimplement this yourself. There are several Bitcoin libraries out there that can do this for you, in various languages.</p>

CC BY-SA 4.0
2021-08-27T16:36:14.370Z
Yeah, this is exactly what I was looking for, thank you very much for the response.  Just so I'm clear, the purpose of doing the base58 check is to determine which of the 3 types of address you are working with indicated by the first byte (byte 0), then subsequent bytes are used as the hash in the output? Do I have that correct?  I am trying to write this logic myself for educational purposes.
bobandweave
CC BY-SA 4.0
2021-08-27T16:55:41.587Z
Base58Check encoding also includes a checksum to detect typos.
Pieter Wuille
CC BY-SA 4.0
2021-08-27T15:51:41.537Z
2021-08-27T15:59:32.700Z
2021-08-27T15:59:32.700Z
Pieter Wuille
<p>Given a public Bitcoin wallet address 1BdYVvwoxTWMGqJS2Pg6NkVD7RnENVjSac; is pasted into a wallet to send Bitcoins to.  How does the wallet create an output to send coins to the public key associated with this address since it is impossible to derive from the public address?</p>

CC BY-SA 4.0
2021-08-27T03:49:32.120Z
Does this answer your question? [Why is it impossible to derive public key from address?](https://bitcoin.stackexchange.com/questions/7683/why-is-it-impossible-to-derive-public-key-from-address)
m1xolyd1an
CC BY-SA 4.0
2021-08-27T09:28:37.350Z
*"how do wallets determine where to send Bitcoins?"* -- Remember, money isn't really sent to addresses, wallets don't really contain money.  As you know, those are just metaphors.
RedGrittyBrick
CC BY-SA 4.0
2021-08-27T15:23:06.607Z
I rephrased the question to hopefully be more clear.  I'm really trying to understand how to create an output given only the public address.
bobandweave
CC BY-SA 4.0
2021-08-30T07:13:07.137Z
@m1xolyd1an It seems unrelated to the OP question.
Antoine Poinsot
<transactions><wallet><script><public-key><cryptography>
How does a Wallet Create a Transaction when a Public Address Is Provided?
bobandweave
# How does a Wallet Create a Transaction when a Public Address Is Provided?

(Asked by: username_0 on 2021-08-27)

Given a public Bitcoin wallet address 1BdYVvwoxTWMGqJS2Pg6NkVD7RnENVjSac; is pasted into a wallet to send Bitcoins to. How does the wallet create an output to send coins to the public key associated with this address since it is impossible to derive from the public address?

**Tags:** transactions, wallet, script, public-key, cryptography

> **Comments:**
> **username_1**: Does this answer your question? [Why is it impossible to derive public key from address?](https://bitcoin.stackexchange.com/questions/7683/why-is-it-impossible-to-derive-public-key-from-address)  
> **username_2**: *"how do wallets determine where to send Bitcoins?"* -- Remember, money isn't really sent to addresses, wallets don't really contain money.  As you know, those are just metaphors.  
> **username_0**: I rephrased the question to hopefully be more clear.  I'm really trying to understand how to create an output given only the public address.  
> **username_3**: @username_1 It seems unrelated to the OP question.  

---

## 1 answers

### Answer by username_4 on 2021-08-27. Score: 1 | Accepted answer

There are currently 3 types of addresses defined, and each directly encodes a specific scriptPubKey.

* `1...` addresses. These are P2PKH addresses. To construct their scriptPubKey, use [Base58Check](https://en.bitcoin.it/wiki/Base58Check_encoding) decoding, verify the first byte of the result is 0, and then construct the script `OP_DUP OP_HASH160 <byte 1-21 of the Base58Check decode> OP_EQUALVERIFY OP_CHECKSIG`.
* `3...` addresses. These are P2SH addresses. To construct their scriptPubKey, use Base58Check decoding, verify the first byte of the result is 5, and then construct the script `OP_HASH160 <byte 1-21 of the Base58Check decode> OP_EQUAL`.
* `bc1...` addresses. These are native segwit addresses. To construct their scriptPubKey, follow the procedure documented in BIP173 and BIP350.

The prefixes characters/bytes are different for other networks, such as the Bitcoin testnet.

Ideally, you don't need to reimplement this yourself. There are several Bitcoin libraries out there that can do this for you, in various languages.

> **Comments:**
> **username_0**: Yeah, this is exactly what I was looking for, thank you very much for the response.  Just so I'm clear, the purpose of doing the base58 check is to determine which of the 3 types of address you are working with indicated by the first byte (byte 0), then subsequent bytes are used as the hash in the output? Do I have that correct?  I am trying to write this logic myself for educational purposes.  
> **username_4**: Base58Check encoding also includes a checksum to detect typos.  

---

