<p>You are on the right track. The address is derived correctly, it is just not encoded with the right version.</p>

<p>You need to add the testnet network version to the <code>btc.payments.p2pkh</code> call as well.</p>

<p>Something like this should work:</p>



<pre><code>console.log(btc.payments.p2pkh({pubkey, network: btc.networks.testnet}).address);
</code></pre>

<p>The address should then start with <code>m...</code> instead of <code>1...</code>.</p>

<p>More information about the available parameters can be found here: <a href="https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/payments/p2pkh.js" rel="nofollow noreferrer">https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/payments/p2pkh.js</a></p>

CC BY-SA 4.0
2020-01-09T21:38:53.043Z
ecco! a million thanks.  right on point
ekkis
CC BY-SA 4.0
2020-01-09T09:27:47.773Z
2020-01-09T09:27:47.773Z
guggero
<p>I've generated a testnet address like this:</p>



<pre><code>const btc = require('bitcoinjs-lib');
const bip32 = require('bip32');
const bip39 = require('bip39');

var root = bip32.fromSeed(
    bip39.mnemonicToSeedSync('my-twelve-word-seed...'), 
    btc.networks.testnet
);
var pubkey = root.derivePath("m/44'/1'/0'/0/0").publicKey;
console.log(btc.payments.p2pkh({pubkey}).address);
</code></pre>

<p>and for my troubles I end up with this value: <code>14kwGTShacA5hT4uAes7dkNvreuHXuRRf7</code></p>

<p>however, when I test that with BlockCypher (or Blockchain.com or some other explorer), it doesn't seem to recognise it:</p>

<pre><code>curl https://api.blockcypher.com/v1/btc/test3/addrs/14kwGTShacA5hT4uAes7dkNvreuHXuRRf7/balance
</code></pre>

<p>yields</p>

<blockquote>
  <p>{"error": "Address 14kwGTShacA5hT4uAes7dkNvreuHXuRRf7 incompatible
  with current block chain: BTC.test3"}</p>
</blockquote>

<p>notice that according to BIP44 the derivation path for testnet coins is <code>m/44'/1'</code> vs. <code>m/44/0'</code> for mainnet</p>

<p>so what is wrong here?</p>

CC BY-SA 4.0
2020-01-09T08:13:58.100Z
A chain explorer can only know about addresses which have actually been used in a transaction which has been broadcast over the network. Have you tried sending some testnet coins to the address you generated?
Mark H
CC BY-SA 4.0
2020-01-09T21:29:28.343Z
no, but I should be able to get a zero balance.  the problem isn't with whether the address has been used.  it's a format problem
ekkis
<testnet><bip44><blockcypher>
Testnet addresses fail in explorers
ekkis
# Testnet addresses fail in explorers

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

I've generated a testnet address like this:

```
const btc = require('bitcoinjs-lib');
const bip32 = require('bip32');
const bip39 = require('bip39');

var root = bip32.fromSeed(
    bip39.mnemonicToSeedSync('my-twelve-word-seed...'), 
    btc.networks.testnet
);
var pubkey = root.derivePath("m/44'/1'/0'/0/0").publicKey;
console.log(btc.payments.p2pkh({pubkey}).address);

```

and for my troubles I end up with this value: `14kwGTShacA5hT4uAes7dkNvreuHXuRRf7`

however, when I test that with BlockCypher (or Blockchain.com or some other explorer), it doesn't seem to recognise it:

```
curl https://api.blockcypher.com/v1/btc/test3/addrs/14kwGTShacA5hT4uAes7dkNvreuHXuRRf7/balance

```

yields

> {"error": "Address 14kwGTShacA5hT4uAes7dkNvreuHXuRRf7 incompatible
> with current block chain: BTC.test3"}

notice that according to BIP44 the derivation path for testnet coins is `m/44'/1'` vs. `m/44/0'` for mainnet

so what is wrong here?

**Tags:** testnet, bip44, blockcypher

> **Comments:**
> **username_1**: A chain explorer can only know about addresses which have actually been used in a transaction which has been broadcast over the network. Have you tried sending some testnet coins to the address you generated?  
> **username_0**: no, but I should be able to get a zero balance.  the problem isn't with whether the address has been used.  it's a format problem  

---

## 1 answers

### Answer by username_2 on 2020-01-09. Score: 3 | Accepted answer

You are on the right track. The address is derived correctly, it is just not encoded with the right version.

You need to add the testnet network version to the `btc.payments.p2pkh` call as well.

Something like this should work:

```
console.log(btc.payments.p2pkh({pubkey, network: btc.networks.testnet}).address);

```

The address should then start with `m...` instead of `1...`.

More information about the available parameters can be found here: <https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/payments/p2pkh.js>

> **Comments:**
> **username_0**: ecco! a million thanks.  right on point  

---

