> 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/ethereum/websocket-stream.md).

# WebSocket 流

&#x20;与 HTTP 不同，使用 WebSockets，当您需要特定信息时，您无需不断发出请求。WebSockets 会为您维护网络连接（如果操作正确）并监听更改。您可以在[**此处查看官方文档**](https://ethereum.org/ml/developers/tutorials/using-websockets/)**。**

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

```
wscat -c wss://api.chainup.net/ws/ethereum/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/ethereum/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/ethereum/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 %}
