Basically I'm trying to create a system in which each user has it's own address to deposit on the site, however I'm having issues with monitoring addresses as they appear to be different results within CLI & Node.
Here's the code used to import the private key based on derived user ID:
const { exec } = require('child_process');
const hdNode = bitcoinjs.bip32.fromBase58(config.BIP32_DERIVED_PRIVATE, bitcoinjs.networks.bitcoin);
exec('bitcoin-cli importprivkey "' + hdNode.derive(user.id).toWIF() + '" "' + email + '" false');
Okay, now for the user side of things, the derived key is displayed using the following:
var derivedPubKey = config.BIP32_DERIVED;
if (!derivedPubKey)
throw new Error('Must set env var BIP32_DERIVED_KEY');
const hdNode = bitcoinjs.bip32.fromBase58(derivedPubKey, bitcoinjs.networks.bitcoin);
exports.deriveAddress = function(index) {
return bitcoinjs.payments.p2pkh({
pubkey: hdNode.derive(index).publicKey,
network: bitcoinjs.networks.bitcoin
}).address;
};
However both results appear to be completely different? if I type bitcoin-cli listreceivedbyaddress 1 true
into my SSH I get the following result:
But then for this same account, on the user interface I get the following: