Created
June 14, 2019 19:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to get the private key