Tonight I was messing around with bitcoin.js and decided to see if I can generate addresses using xpub only. So far, the code works, but the address it generated doesnt show up on electrum. I decided to send a couple of cents to the address and it have been received by the address but still have yet to show up in electrum or the ledger bitcoin app and dont know what went wrong. I did check blockchain.info to see if the address is listed there with the xpub but no luck either. Maybe someone can point out where I went wrong.
var bitcoin = require('bitcoinjs-lib');
var HDNode = bitcoin.HDNode;
var xpub = HDNode.fromBase58("xpub...");
for(i = 0;i<5;i++){
console.log(xpub.derive(0).derive(i).getAddress());
}
I am mainly trying to figure this out so I do not have to worry about having an electrum daemon running to handle it.
EDIT: I think I figured it out... need to use xpub.derive when getting the address. Someone can correct me though if im wrong.
EDIT: Updated Code. I did compare it against the list of addresses listed on electrum and so far they match. Any reason why I must use "derive(0).derive(...)" instead of just "derive(...)"? I may go back and reread the document I saw earlier since I couldve missed something.