Skip to content

Instantly share code, notes, and snippets.

@gunar
Created June 14, 2019 19:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gunar/86c05f67e2a862f148bda1fc4f0a82f3 to your computer and use it in GitHub Desktop.
Save gunar/86c05f67e2a862f148bda1fc4f0a82f3 to your computer and use it in GitHub Desktop.
Safely Generate Electrum-valid P2PKH Addresses From Your HD Wallet's XPUB key
'use strict'
const { HDPublicKey, PublicKey, Address, Networks } = require('bitcore-lib')
const xpubkey = 'xpub...'
const hdPublicKey = HDPublicKey(xpubkey);
// We'll generate the first 20 addresses (default number of addresses that Electrum shows you)
for (let i = 0; i < 20; i++) {
const orderPublicKey = hdPublicKey.deriveChild(`m/0/${i}`)
// or
// const orderPublicKey = hdPublicKey.deriveChild(0).deriveChild(i)
var pubkey = PublicKey(orderPublicKey.publicKey)
var address = Address.fromPublicKey(pubkey/* , Networks.testnet */)
console.log("address", address)
}
@markashh
Copy link

how to get the private key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment