<p>Raghav Sood: you are right: here the correct code:</p>

<pre><code>const addresses = bitcoinjs.address.fromOutputScript(outputScript, bitcoinjs.networks.testnet);
</code></pre>

<p>Thanks :-)</p>

CC BY-SA 4.0
2019-11-06T15:28:44.470Z
2019-11-06T15:28:44.470Z
jfjobidon
<p>I use nodejs with this npm library:</p>

<pre><code>const bitcoinjs = require('bitcoinjs-lib');  // version "^5.1.6"
</code></pre>

<p>I received a rawTx from zeroMq, then extract it:</p>

<pre><code>const tx = bitcoinjs.Transaction.fromHex(rawTx);
</code></pre>

<p>the txID is 8dba72608cbfca197b55d86aae2817d11f829b9361eb421fb005616f48ce8401</p>

<p>if I take the first output:</p>

<pre><code>let output = tx.outs[0];
</code></pre>

<p>then I try to get the address:</p>

<pre><code>const scriptBuffer = Buffer.from(output.script);
const address = bitcoinjs.address.fromOutputScript(scriptBuffer);
</code></pre>

<p>I get: </p>

<blockquote>
  <p>37XE9EYzix7S42fLMxutrNaPfDbCccLhiT</p>
</blockquote>

<p>But from bitcoin core I get:</p>

<blockquote>
  <p>2My5SCyV2LQcnFpHt36XmUKZesZoNRQRPa5</p>
</blockquote>

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

CC BY-SA 4.0
2019-11-05T22:01:24.147Z
You need to tell bitcoinjs to use the testnet settings
Raghav Sood
CC BY-SA 4.0
2019-11-06T04:54:35.137Z
@Raghav Sood You should turn that into an answer.
Pieter Wuille
<bitcoin-core><address><zeromq>
Cannot get the same address format from zeroMQ and Bitcoin Core
jfjobidon
# Cannot get the same address format from zeroMQ and Bitcoin Core

(Asked by: username_0 on 2019-11-05)

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:

> 37XE9EYzix7S42fLMxutrNaPfDbCccLhiT

But from bitcoin core I get:

> 2My5SCyV2LQcnFpHt36XmUKZesZoNRQRPa5

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

**Tags:** bitcoin-core, address, zeromq

> **Comments:**
> **username_1**: You need to tell bitcoinjs to use the testnet settings  
> **username_2**: @username_1 You should turn that into an answer.  

---

## 1 answers

### Answer by username_0 on 2019-11-06. Score: 1

username_1 username_1: you are right: here the correct code:

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

```

Thanks :-)


---

