Why are there different addresses?
Which of these addresses should I use?
The Bitcoin community is a community with ever-evolving technology, and the development of technology produces new content. Different address formats can be considered the result of the application of new technologies. Next, let's explore the differences between different address formats.
01 Legacy Address (P2PKH)
This format was adopted when Bitcoin was first launched in 2009, so it is called the Legacy format. Because the Bitcoin address was created from a public key/private key pair at that time, it is also called a Pay Public Key Hash (P2PKH) address.
At present, it seems that Legacy type addresses will take up more space in transactions, resulting in higher transaction fees. At present, people will only use this type of address when using some old wallets that are incompatible with new addresses.
It can be found that Legacy addresses have a feature that the addresses all start with "1". This is because when generating addresses, a prefix will be added to the generated public key according to different scenarios (such as: test network/main network). After the public key with the prefix is calculated by Hash, the address will eventually start with "1".
02 Nested SegWit Address (P2SH-P2WPKH)
Compared with the traditional Legacy address, the P2SH address uses the hash of the redeem script instead of the public key. In layman's terms, P2PKH pays to the hash of a public key, while P2SH pays to the redeem script. The funds in the redemption script can only be spent after the recipient meets the transfer conditions of the redemption script.
Since the object of payment is converted from the public key to the script, the flexibility is greatly expanded, and the execution logic of the redemption script can be customized. Typical applications include implementing multi-signature transactions.
Based on P2SH, if the segregated witness technology is embedded, the format of this address is the segregated witness compatible address (Nested SegWit). You can learn about the content related to the segregated witness when introducing the segregated witness address. After the introduction of the segregated witness technology, the transaction volume can be reduced, thereby reducing the transaction fee.
You can see that the P2SH address starts with "3".