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?
3Does this answer your question? Why is it impossible to derive public key from address?– m1xolyd1anAug 27, 2021 at 3:49
"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.– RedGrittyBrickAug 27, 2021 at 9:28
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.– bobandweaveAug 27, 2021 at 15:23
@m1xolyd1an It seems unrelated to the OP question.– Antoine PoinsotAug 30, 2021 at 7:13
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 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.
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. Aug 27, 2021 at 16:36
Base58Check encoding also includes a checksum to detect typos. Aug 27, 2021 at 16:55