Derive public LTC addresses from an extended public LTC address in xpub format
See original GitHub issueHello everybody! I’m very new to JS, nodeJS and bitcoinjs, so please excuse my noobidity.
Im trying to derive public LTC addresses from an extended LTC address in xpub format (created by Jaxx and exported by Exodus). For demonstration purposes, I created (in Jaxx) and exported (in Exodus) a wallet with the following mnemonic:
quit disagree kiss among move interest orchard trade bullet forward usual neither
The extended public LTC address is: xpub6CAp1aH6mzGrH3hkCuaZPCDrgTMkPm55xhBpNETbPPuhAxxoprvsiHBDipL7ePY6aAiZZThyWCN5qiKcCZxtjCJLtVjAeVryZCtamBKyi3m
And the first public LTC address is: LeUD63jWGkLTohEWq6t4gyqpithtnReXEk
I ran some tests with https://iancoleman.io/bip39/ and they yielded the info, that the derivation path is: m/44’/2’/0’/0
So far, I got the following code:
var network = bitcoin.networks.litecoinXprv;
var xpub = 'xpub6CAp1aH6mzGrH3hkCuaZPCDrgTMkPm55xhBpNETbPPuhAxxoprvsiHBDipL7ePY6aAiZZThyWCN5qiKcCZxtjCJLtVjAeVryZCtamBKyi3m'
var node = bitcoin.HDNode.fromBase58(xpub,network)
var address = bitcoin.HDNode.fromBase58(xpub,network).derivePath("m/44'/2'/0'/0").derive(0).getAddress();
// Possible alternative?
//var address = node.derive(44).derive(2).derive(0).derive(0).derive(0).getAddress()
console.log("First address: " + address)
Thanks for bitcoinjs and any provided support.
EDIT: I added the missing apostrophes.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
var address = bitcoin.HDNode.fromBase58(xpub, network).derive(0).derive(0).getAddress();
Your xpub is @
m/44'/2'/0'
exported, so you import and derive the last0/0
and gets you them/44'/2'/0'/0/0
Usually when you export xprv, you export
m
but when you export xpub you export the LAST hardened path: (0'
inm/44'/2'/0'/0/0
)@junderw Thanks! That did the job. I’m glad that it is indeed possible to derive the addresses without providing the extended private key.
Here is the complete code: