<p><code>bitcoin-cli</code> is generating a P2WPKH address (<code>bc1...</code>), but then on the user side you are generating a P2PKH address (<code>1....</code>). </p>

<p>You may also need to check to ensure the same address derivation path is being used (Bitcoin-core uses hardened derivation).</p>

<p>For more info on address encodings see:</p>

<p><a href="https://bitcoin.stackexchange.com/questions/64733/what-is-p2pk-p2pkh-p2sh-p2wpkh-eli5">What is P2PK, P2PKH, P2SH, P2WPKH - ELI5</a></p>

<p><a href="https://bitcoin.stackexchange.com/questions/66428/what-is-the-size-of-different-bitcoin-transaction-types/75124#75124">What is the size of different Bitcoin transaction types?</a></p>

CC BY-SA 4.0
2020-01-12T23:33:45.093Z
2020-01-12T23:33:45.093Z
chytrik
<p>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 &amp; Node.</p>

<p>Here's the code used to import the private key based on derived user ID:</p>

<pre><code>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');
</code></pre>

<p>Okay, now for the user side of things, the derived key is displayed using the following:</p>

<pre><code>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;
};
</code></pre>

<p>However both results appear to be completely different? if I type <code>bitcoin-cli listreceivedbyaddress 1 true</code> into my SSH I get the following result:
<a href="https://i.sstatic.net/9CQzN.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/9CQzN.png" alt="enter image description here"></a></p>

<p>But then for this same account, on the user interface I get the following:
<a href="https://i.sstatic.net/DSitP.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/DSitP.png" alt="enter image description here"></a></p>

<bitcoind><bip32-hd-wallets><node.js>
Derived address different from CLI to NodeJS
Curtis
# Derived address different from CLI to NodeJS

(Asked by: username_0 on 2020-01-12)

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:

**Tags:** bitcoind, bip32-hd-wallets, node.js


---

## 1 answers

### Answer by username_1 on 2020-01-12. Score: 1

`bitcoin-cli` is generating a P2WPKH address (`bc1...`), but then on the user side you are generating a P2PKH address (`1....`).

You may also need to check to ensure the same address derivation path is being used (Bitcoin-core uses hardened derivation).

For more info on address encodings see:

[What is P2PK, P2PKH, P2SH, P2WPKH - ELI5](https://bitcoin.stackexchange.com/questions/64733/what-is-p2pk-p2pkh-p2sh-p2wpkh-eli5)

[What is the size of different Bitcoin transaction types?](https://bitcoin.stackexchange.com/questions/66428/what-is-the-size-of-different-bitcoin-transaction-types/75124#75124)


---

