Skip to content

Problem generating SegWit addresses. #1015

@NeuralChris

Description

@NeuralChris

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 ) );
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions