Using P2WPKH
How to use P2WPKH in OP_NET
OP_NET provides two ways to access P2WPKH addresses. Use the p2wpkh property on a wallet object to retrieve the P2WPKH address directly. Alternatively, call the p2wpkh() method on an Address object, which allows specifying the target network as a parameter.
The following example shows how to use both ways:
typescript
// Mainnet Legacy
const p2wpkhMainnet = wallet.p2wpkh;
console.log('P2WPKH Mainnet:', p2wpkhMainnet);
// Output: bc1q...
// Validate key
const isP2WPKHValid = AddressVerificator.isP2WPKHAddress(p2wpkh, networks.bitcoin);
console.log('P2WPKH valid:', isP2WPKHValid); // true
// Testnet Legacy
const p2wpkhTestnet = wallet.address.p2wpkh(networks.testnet);
console.log('P2WPKH Testnet:', p2wpkhTestnet);
// Output: tb1q...