-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
I'm trying to generate a SegWit address using my wallet's public key and it doesn't seem to be working. I've tried two different transactions using the addresses generated and neither of them came through to the receiving wallet.
let btc_node = Bitcoin.HDNode.fromBase58( "[xpub key]" );
for( let i = 0; i < 3; i++ ) {
let btc_node_derivation = btc_node.derive( i );
let redeem_script = Bitcoin.script.witnessPubKeyHash.output.encode( Bitcoin.crypto.hash160( btc_node_derivation.getPublicKeyBuffer() ) );
// Generate P2SH address instead of Bech32 for backwards compatibility
let script_pub_key = Bitcoin.script.scriptHash.output.encode( Bitcoin.crypto.hash160( redeem_script ) );
console.log( "segwit address", Bitcoin.address.fromOutputScript( script_pub_key ) );
}