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