Person A holds a bitcoin and he wants to transfer it to Person B. This transaction will have a input which holds the unlocking script and output which holds the locking script. So in the transaction's locking scrip(ScriptPubkey) a public key has to be added. My understanding is this locking script will contain Person B's public key. But how will person A get person B's public key to create the transaction?
Asked
Active
Viewed 732 times
-1
-
As the tag says **general Bitcoin questions belong on https://bitcoin.stackexchange.com** but briefly: since about 2010 most bitcoin transactions use an _address_ which is a _hash_ of the publickey, called P2PKH (Pay to Public Key Hash) or since 2017 often P2WPKH (Pay to Witness Public Key Hash, part of a scheme called 'segwit' to make bitcoin block processing more efficient). People/systems can provide or distribute their addresses in lots of ways, often as encoded strings that look like 1asdfasdfasdfasdf or bc1asdfasdfasdfasdfasdf. – dave_thompson_085 Oct 26 '21 at 08:03
1 Answers
-1
As dave_thompson_085 has pointed out, most bitcoin transactions do not actually contain the public key as part of an output script and instead contain the hash of the public key or the hash of a script. There is an old scheme known as P2PK
where the public key is part of the output script but this is almost never used today in favour of P2PKH
, P2WPKH
and soon P2TR
.
As for communicating the required information to create a transaction, an address is used to encode the hash of the public key or script with different output script variations using different encoding variations to indicate what output script should be used.
Here are some of the encoding schemes for common locking scripts:
P2PKH
uses Base58 check encoding where the encoded data consists of a version prefix of0x00
for mainnet followed by theHash160
of the receiving public key. This results in an address starting with the character1
.P2SH
uses Base58 check encoding where the encoded data consists of a version prefix of0x05
for mainnet followed by theHash160
of the redeem script. This results in an address starting with the character3
.P2WPKH
uses Bech32 encoding where the encoded data consists of a witness version followed by theHash160
of the public key. The witness version for segwit outputs is0
and results in the address starting withbc1q
.P2WSH
uses Bech32 encoding where the encoded data consists of a witness version followed by theSHA256
of the script. BecauseP2WSH
usesSHA256
as opposed toHash160
, the address is longer thanP2WPKH
addresses. The address also starts withbc1q
.P2TR
uses Bech32m encoding where the encoded data consists of the witness version followed by the tweaked key unhashed. The witness version here is1
and results in the addressbc1p
.
If your question is regarding the actual transmission of Person B's address to Person A, there is no official method to do this. However if you want to check if an address received is valid, the checksum at the end of each encoded address can be used. For addresses encoded in Base58, the checksum is the last 4 characters and for Bech32 it is the last 6 characters. Bech32 also has error correcting capability as per [BIP-0173][1]

nlanson
- 357
- 1
- 3
- 14