question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem generating SegWit addresses.

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
dabura667commented, Mar 6, 2018

Ethereum ledger is not BIP44 compliant and there is no concept of change which is why it worked and bitcoin didn’t.

2reactions
dabura667commented, Mar 6, 2018

Derive the change layer first.

Change

.derive( i )

To

.derive(0).derive(i)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue generating private Key and segwit address with python
I used the following script to generate my private key and the corresponding segwit address. Then to test it, i sent funds to...
Read more >
Generate segwit address from public key · Issue #1667 - GitHub
Hi, I am new to bitcoinJ, and previously I was using bitcoinJS to generate the address which is very slow. The js code...
Read more >
Hundreds of Bitcoin Cash Are Stuck in Segwit Addresses
Hundreds of thousands of dollars worth of BCH is languishing in segwit addresses. The funds were mistakenly sent there by users who have...
Read more >
Segregated Witness (SegWit): Definition, Purpose, How It Works
The Main Issue SegWit Addressed. When one user sends another user some Bitcoin, two pieces of information are required: a public address and...
Read more >
Bitcoin SegWit Wallet Address Calculation - c++ - Stack Overflow
The above code in my question will work quite happily for p2pkh address generation for Bitcoin/Litecoin etc, but when generating a Q (for ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found