I want to generate a new receiving address for my bitcoin wallet for each new user. Bitcoin transferred to all these address should be received in my bitcoin wallet. I don’t want to expose my private key or seed on the server.I found that this is how HD wallets work so I tried this.
const bip39 = require('bip39') const bitcoin = require('bitcoinjs-lib') //ver 3.0.2 let phrase = 'width humor wheat sad obscure outer ancient grab edit labor record express devote humble recipe occur refuse tooth original fluid learn scheme fuel assault'; let seedBuffer = bip39.mnemonicToSeedSync(phrase) // <Buffer 85 19 18 81 cf 0e cc f7 9c 5d 61 ...... let masterNode = bitcoin.HDNode.fromSeedBuffer(seedBuffer) // Deriving the first account based on BIP44 let account0 = masterNode.derivePath("m/44'/0'/0'") let xpubString = account0.neutered().toBase58() console.log(xpubString) let address0FromXpub = bitcoin.HDNode.fromBase58(xpubString) let address0 = address0FromXpub.derivePath("0/0").keyPair.getAddress() let address1 = address0FromXpub.derivePath("0/1").keyPair.getAddress() let address2 = address0FromXpub.derivePath("0/2").keyPair.getAddress() let address3 = address0FromXpub.derivePath("0/3").keyPair.getAddress() // address0.toBase58() console.log("address0",address0) console.log("address1",address1) console.log("address2",address2) console.log("address3",address3)
but I tried sending bitcoin to the generated address and didn’t received any? If anyone could help.