> For the complete documentation index, see [llms.txt](https://docs.chainupcloud.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.chainupcloud.com/zhong-wen/qu-kuai-lian-api/bsc/websocket-stream.md).

# WebSocket stream

Unlike HTTP, with WebSockets, you don't need to continuously make requests when you want specific information. WebSockets maintain a network connection for you (if done right) and listen for changes . You may view the official documentation [here](https://docs.bnbchain.org/docs/Integrate#the-recommended-way-via-websocket).&#x20;

{% tabs %}
{% tab title="WebSocket" %}

```
wscat -c wss://api.chainup.net/ws/bsc/mainnet/<YOUR_API_KEY>
<  {"jsonrpc":  "2.0", "id": 0, "method":  "eth_gasPrice"}
<  {"jsonrpc": "2.0","id":0,"result":"0x6f56b59ac"}
```

{% endtab %}

{% tab title="Javascript" %}

<pre><code><strong>const Web3 = require('web3');
</strong>
const web3 = new Web3("wss://api.chainup.net/ws/bsc/mainnet/&#x3C;YOUR_API_KEY>")

web3.eth.getBlockNumber().then(console.log) // -> 9022457

</code></pre>

{% endtab %}

{% tab title="Python" %}

```
from web3 import Web3

websocket_url='wss://api.chainup.net/ws/bsc/mainnet/<YOUR_API_KEY>'
w3 = Web3(Web3.HTTPProvider(websocket_url))

# You can check if the connection is established using isConnected function.
w3.isConnected()

# Output: True
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.chainupcloud.com/zhong-wen/qu-kuai-lian-api/bsc/websocket-stream.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
