Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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)
Copy link

markashh commented Nov 18, 2019

how to get the private key

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