Testnet addresses fail in explorers 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?
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