Closed Mr-Mondragon closed 5 years ago
For 2, in the p2sh example try replacing p2wpkh({ pubkey: keyPair.publicKey })
in your source with p2wpkh({ address: address_p2wpkh })
and see what happens
Crystal clear, thank you so much Jonathan! Very happy user of Bitcoin-js here! 😃
Given a private key, I can generate its corresponding P2WPKH address as well as its segwit P2SH address like this:
Three questions:
The P2WPKH address is by default bech32 encoded, whereas the P2SH version is by default Base58Check encoded. As far as I understand, bech32 and Base58Check are just two different ways of encoding data. Is it just convention or common practice to use bech32 for P2WPKH addresses and Base58Check for P2SH addresses? Would it also be technically OK (although most wallets probably won't support it) to do the opposite, i.e. use Base58Check encoding for a P2WPKH address, and bech32 encoding for a P2SH address, or is there a more fundamental reason to this convention?
Besides the difference in encoding, am I correct that the P2WPKH address actually contains different data than the P2SH address? More specifically, the P2WPKH would be a hash of a public key, and the P2SH is a hash of a script (a segwit script to be exact). This also means one cannot be derived from the other, i.e. I cannot convert a P2WPKH address into a P2SH one or vice versa, correct?
If someone sends me bitcoins, does it matter if they send it to the P2WPKH or P2SH address? As long as I have the private key, I can always generate either address and thus spend from the one it was sent to, right?