I use nodejs with this npm library:

const bitcoinjs = require('bitcoinjs-lib');  // version "^5.1.6"

I received a rawTx from zeroMq, then extract it:

const tx = bitcoinjs.Transaction.fromHex(rawTx);

the txID is 8dba72608cbfca197b55d86aae2817d11f829b9361eb421fb005616f48ce8401

if I take the first output:

let output = tx.outs[0];

then I try to get the address:

const scriptBuffer = Buffer.from(output.script);
const address = bitcoinjs.address.fromOutputScript(scriptBuffer);

I get:


But from bitcoin core I get:


My question: how do I convert the address to the same format as bitcoin core ?

  • 1
    You need to tell bitcoinjs to use the testnet settings Nov 5, 2019 at 22:01
  • @Raghav Sood You should turn that into an answer. Nov 6, 2019 at 4:54

1 Answer 1


Raghav Sood: you are right: here the correct code:

const addresses = bitcoinjs.address.fromOutputScript(outputScript, bitcoinjs.networks.testnet);

Thanks :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.