Home > web3.0 > body text

Web3 Newbie Series: Why does my Bitcoin have multiple addresses?

WBOY
Release: 2024-06-04 22:16:10
Original
1050 people have browsed it

There may be many novice friends like the author. When they used the WEB3 wallet for the first time, they happily opened the Bitcoin wallet and prepared to copy the address, but suddenly found that a wallet they created actually had multiple different addresses. It's like walking to an unfamiliar crossroads, with a confused look on your face.

Why are there different addresses? Which of these addresses should be used?

<img src="https://img.php.cn/upload/article/000/000/000/171751057878929.png" alt="Web3 Newbie Series: Why does my Bitcoin have multiple addresses?">OKX 钱包的多个 Bitcoin 地址
Copy after login

What are these addresses

The Bitcoin community is a community where technology is constantly developing, and the development of technology produces new content. Different address formats can be considered a result of the application of new technologies. Next, explore the differences between different address formats.

Legacy address (P2PKH)

This format was adopted when Bitcoin was first launched in 2009, so it is called Legacy format, and because the Bitcoin address at that time was derived from the public key /Private key pair is created, so it is also called a payment public key hash (P2PKH) address.

Currently, it seems that Legacy type addresses will take up more space in transactions, resulting in higher transaction fees. Currently, people will only use this type of address when using some old wallets that are incompatible with the new address.

You can find that Legacy addresses have a characteristic, the addresses all start with "1". This is because when generating an address, a prefix will be added in front of the generated public key according to different scenarios (such as testnet/mainnet). After the public key with the prefix added is calculated through Hash, the address will eventually start with "1".

Nested SegWit Address (P2SH-P2WPKH)

Compared with the traditional Legacy address, the P2SH address does not use the hash of the public key, but the hash of the redemption script (redeem-script) Hash. In layman's terms, P2PKH pays to the hash of a public key, while P2SH pays to the redemption script. Only after the recipient meets the transfer conditions of the redemption script can the funds inside be spent.

Since the payment object is converted from a public key to a 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 Segregated Witness technology is embedded, then the format of this address is Segregated Witness compatible address (Nested SegWit). You can learn more about Segregated Witness when introducing the Segregated Witness address. After the introduction of Segregated Witness technology, the volume of transactions can be reduced, thereby reducing transaction fees.

You can see that the P2SH address starts with "3".

Native SegWit Address

Before introducing this type of address, we need to introduce the key technology inside - Segregated Witness (SegWit). As the name suggests, Segregated Witness isolates the witness data (witness) and processes it separately.

A significant advantage of doing this is that it reduces the size of transaction information, thereby reducing transaction fees. Another benefit brought by the reduction in size is that the upper limit of Bitcoin block transaction size has been increased from 1 MB to 4 MB.

The characteristic of the Segregated Witness address is that the address starts with "bc1".

Taproot address (Taproot)

The advantages of Taproot address are privacy and efficiency in complex transaction scenarios. Compared with Native SegWit, it uses the Schnorr algorithm to replace the elliptic curve digital signature algorithm. The former is more efficient in batch transaction scenarios and improves the privacy of multi-signature wallets.

The main root address is characterized by the address generally starting with "bc1q".

What address format should I choose?

The current mainstream wallets such as OKX, Unisat and other wallets support the above four addresses. Therefore, in order to reduce transaction costs, the addresses using Native SegWit and Taproot formats are More reasonable.

In addition, if you are interested in Bitcoin inscriptions, etc., then these two addresses are your best choice. Most wallets have done additional processing on the inscriptions of these two addresses to protect them. Your special UTXO cannot be mistakenly transferred away in a transaction. Look for the wallet address starting with "bc1"!

Of course, wallets with different address formats can conduct fund transactions, so don’t worry.

If you want to check the balance or block information of Bitcoin, you are welcome to use ZAN’s node service. We provide a rich API for developers to use. API document details: https://docs.zan.top/reference/zan_getbalance-enhance

Go deeper - introduction to key technologies

After the above introduction, everyone Now that I have a preliminary understanding of the wallet, I am very interested in acquiring some of the technologies in the wallet, so let’s take a look at the mysterious technologies inside.

Redeem Script Redeem Script

When introducing P2SH, we knew that this is a technology for redemption script transactions, so what is a redemption script and its role in the Bitcoin ecosystem? What is it.

Before introducing the redemption script, we need to introduce the basic structure of Bitcoin transactions.

The following is a typical P2PK type transaction, in which the address starting with 04ae wants to transfer 10 BTC to the address starting with 15kD. The account with the 04ae address needs to show others on the chain that it indeed has the right to use this account (possess the private key), then he needs to provide a signature (ScriptSig) in this transaction to prove his identity.

In addition to obtaining the signature, the verifier also needs to find the output script of the previous transaction corresponding to the UTXO. These two scripts are spliced ​​together to form the redemption script. The function of the redemption script is to prove the legitimacy of the transaction.

Web3 Newbie Series: Why does my Bitcoin have multiple addresses?

In this transaction, you can see that the signature and output script are both computer instructions. "OP_PUSHBYTES" means PUSH a piece of data into the stack. First, 04ae signs the entire transaction with its own private key in ScriptSig, and the signature will be pushed onto the stack. Then push the public key into the stack, and finally in "OP_CHECKSIG", use the public key to decrypt the signature and compare whether the transaction is consistent. If they are consistent, the identity is valid.

In addition to this P2PK method, the redemption script can also implement different authentication methods such as P2PKH and P2SH.

Segregated Witness

From the above introduction, you can know that the newer wallet formats currently use Segregated Witness technology, so what is Witness and how is it isolated? Woolen cloth.

The Witness here can be thought of as the script signature (scriptSig) information in the basic structure of Bitcoin. Segregated Witness extracts it from the basic structure and puts it in a new data structure.

Web3 Newbie Series: Why does my Bitcoin have multiple addresses?

As you can see in the above figure, the only necessary content in the transaction is the transaction source information and transaction output information. The size of the transaction is reduced, due to the yellow Parts (the total size of a transaction) are limited in size, so transmitting transaction signatures separately allows a block to accommodate more transactions. In addition, when calculating the signature of a transaction, the content of the signature part is not counted, so the problem of transaction malleability can be effectively solved.

The following is a P2TR transaction. You can see that this transaction has an additional Witness part. Its function is to verify the legitimacy of the transaction. After using Witness instead of ScriptSig, the method of verifying legitimacy is still the same, that is, by using the public key to decrypt the signature of Witness to verify whether the content of the transaction is consistent. Nodes will request Witness information only when they need to verify the legitimacy of the transaction. Now use the ZAN Node service for free (visit ZAN.TOP) to connect to the BTC network stably and at high speed.

Web3 Newbie Series: Why does my Bitcoin have multiple addresses?

To summarize, Segregated Witness separates the transaction signature part from the rest of the original transaction, thereby reducing the size of a single transaction and improving the overall efficiency of the transaction. The capacity of the block. In addition, since the content of the signature part is not included in the calculation of the hash value of the transaction, it can effectively solve the problem of transaction malleability .

This article is written by Yeezo (X account @GaoYeezo75065) of ZAN Team (X account @zan_team).

The above is the detailed content of Web3 Newbie Series: Why does my Bitcoin have multiple addresses?. For more information, please follow other related articles on the PHP Chinese website!

source:panewslab.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template