<p>I faced the same problem and the solution is to listen to all transactions and to detect the transaction sent to our address in this way, I tried a method and it works fine.</p>
<pre><code>ws.addEventListener('open', () =&gt; {
    ws.send(JSON.stringify({
        &quot;op&quot;: &quot;unconfirmed_sub&quot;
    }));
});

ws.addEventListener('message', (res) =&gt; {
    let data = JSON.parse(res.data);
    let outs = data.x.out;
    let out = outs.find(o =&gt; {
        return String(o.addr).toLowerCase() == receiver.toLowerCase();
    });
    if (out) {
        setTimeout(() =&gt; {
           startCallback(data);
        }, 6000);
    }
});
</code></pre>

CC BY-SA 4.0
2023-08-17T10:27:44.970Z
2023-08-17T10:30:59.057Z
2023-08-17T10:30:59.057Z
BeycanDeveloper
<p>I'm having trouble receiving WebSocket messages for address-related events. Here is the code that I'm using (trackAddress gets called externally and I'm sure it sends the right thing). I also tried from an online WebSocket client (as seen in the photo) and the response to ping_tx is not the right transaction (the docs state that if you are subscribed to an address it would be that address's last transaction), instead, it returns the most recent on the whole network. It's really frustrating but I do not understand what it is that I am doing wrong. It's as if I'm never really subscribing to it...</p>
<p>You can see the transaction here: <a href="https://www.blockchain.com/explorer/addresses/btc/1P8wXFz6F7UdqnfsByZUf6tBxukcp9bJE9" rel="nofollow noreferrer">https://www.blockchain.com/explorer/addresses/btc/1P8wXFz6F7UdqnfsByZUf6tBxukcp9bJE9</a></p>
<pre class="lang-js prettyprint-override"><code>import { WebSocket } from &quot;ws&quot;

const ws = new WebSocket(&quot;wss://ws.blockchain.info/inv&quot;)

setInterval(() =&gt; {
    ws.ping()
}, 30000)

ws.on(&quot;open&quot;, async() =&gt; {
    console.log(`Listener connected to ${ws.url}`)
})

ws.on(&quot;close&quot;, () =&gt; {
    console.log(&quot;Listener disconnected&quot;)
})

ws.on(&quot;message&quot;, (data =&gt; {
    const res = JSON.parse(data.toString())

    console.log(res)
}))

export const trackAddress = (address: string) =&gt; {
    console.log(`Tracking address ${address}`)
    ws.send(JSON.stringify({
        op: &quot;addr_sub&quot;,
        addr: address
    }))
}
</code></pre>
<p><a href="https://i.sstatic.net/rncmR.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/rncmR.png" alt="enter image description here" /></a></p>

<blockchain><address><api><websockets>
Blockchain API not sending subscribed info
DreamY
# Blockchain API not sending subscribed info

(Asked by: username_0 on 2023-08-09)

I'm having trouble receiving WebSocket messages for address-related events. Here is the code that I'm using (trackAddress gets called externally and I'm sure it sends the right thing). I also tried from an online WebSocket client (as seen in the photo) and the response to ping\_tx is not the right transaction (the docs state that if you are subscribed to an address it would be that address's last transaction), instead, it returns the most recent on the whole network. It's really frustrating but I do not understand what it is that I am doing wrong. It's as if I'm never really subscribing to it...

You can see the transaction here: <https://www.blockchain.com/explorer/addresses/btc/1P8wXFz6F7UdqnfsByZUf6tBxukcp9bJE9>

```js
import { WebSocket } from "ws"

const ws = new WebSocket("wss://ws.blockchain.info/inv")

setInterval(() => {
    ws.ping()
}, 30000)

ws.on("open", async() => {
    console.log(`Listener connected to ${ws.url}`)
})

ws.on("close", () => {
    console.log("Listener disconnected")
})

ws.on("message", (data => {
    const res = JSON.parse(data.toString())

    console.log(res)
}))

export const trackAddress = (address: string) => {
    console.log(`Tracking address ${address}`)
    ws.send(JSON.stringify({
        op: "addr_sub",
        addr: address
    }))
}

```

[![enter image description here](https://i.sstatic.net/rncmR.png)](https://i.sstatic.net/rncmR.png)

**Tags:** blockchain, address, api, websockets


---

## 1 answers

### Answer by username_1 on 2023-08-17. Score: 1

I faced the same problem and the solution is to listen to all transactions and to detect the transaction sent to our address in this way, I tried a method and it works fine.

```
ws.addEventListener('open', () => {
    ws.send(JSON.stringify({
        "op": "unconfirmed_sub"
    }));
});

ws.addEventListener('message', (res) => {
    let data = JSON.parse(res.data);
    let outs = data.x.out;
    let out = outs.find(o => {
        return String(o.addr).toLowerCase() == receiver.toLowerCase();
    });
    if (out) {
        setTimeout(() => {
           startCallback(data);
        }, 6000);
    }
});

```


---

