Convert P2PKH to P2SH addresses: a guide
The underlying blockchain from Ethereum consists of two types of addresses: P2PKH and P2SH. While both addresses are used for transactions, they differ in their structure and use cases. In this article, we will deal with the process of converting a P2PKH address to a P2SH address and examine whether the balance of the former is transmitted to the latter.
P2PKH address structure
A P2PKH address is shown by a hexadecimal string that begins with “0x”, followed by a 45 (represents a public key -hash). The remaining part of the string consists of a sequence of characters, with each character a byte. In general, this format looks like:
0x ... 00000123456789012345678901234567890123456789
P2SH address structure
A P2SH address is also shown by a hexadecimal string, but the first 45 bytes differ from those in a P2PKH address. The key difference lies in the use of 0x ...
instead of 0x
. This enables a more compact display.
Convert P2PKH to P2SH addresses
To convert a P2PKH address into a P2SH address, you have to replace the first 45 bytes with 0x ... 0000012345678901234567890123456789.
0xbecomes 0x
... 00000123456789012345678901234567890123456789"
If you convert a P2PKH address, the resulting hexadecimal character is longer than 45 characters. For instance, if we take the Address0x … 00000123456789012345678901234567891And Replace
0x, we get
P2SH: 0x … 00000123489012345 78901234567891.
Is the remaining amount transferred?
In general, the balance of a P2PKH address is transferred to a corresponding P2SH address. However, this is not always the case.
If you create a new Ethereum account from a P2PKH address using a public key, the balance connected to this key remains and can be transferred directly to a P2SH address. This is known as "address reuse".
However, if you reuse a P2PKH address for an existing Ethereum account, the remaining amount will not transfer to the new address. Instead, you would have to create a new Ethereum letter bag with the updated public key.
Diploma
Converting P2PKH addresses in P2SH addresses is possible, but the first 45 bytes of the hexadecimal string must be replaced by0x …`. When reused the public key of an existing Ethereum account, the remaining amount will not be transferred to a new address. Nevertheless, this process can be useful to create several addresses from the same seed phrase or the same private key.
If you are interested in researching more advanced topics related to Ethereum addresses and balance sheets, e.g. B. Setting, delegating or using different types of addresses (such as P2SH -multi), you are welcome to ask yourself!