> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chainstack.com/llms.txt
> Use this file to discover all available pages before exploring further.

# net_listening | Avalanche

Avalanche API method that returns a boolean value indicating whether the client is currently listening for network connections or not. The `net_listening` method can be useful in many scenarios where it is important to monitor the status of an Avalanche client's network connection to ensure that it is working properly.

<Check>
  **Get your own node endpoint today**

  [Start for free](https://console.chainstack.com/) and get your app to production levels immediately. No credit card required.

  You can sign up with your GitHub, X, Google, or Microsoft account.
</Check>

## Parameters

* `none`

## Response

* `boolean` — a boolean value that indicates whether or not a node is currently actively seeking peer connections. `true` if the client is actively listening for connections, `false` if not.

## `net_listening` code examples

<CodeGroup>
  ```javascript web3.js theme={"system"}
  const Web3 = require("web3");
  const NODE_URL = "CHAINSTACK_NODE_URL";
  const web3 = new Web3(NODE_URL);

  async function isListening() {
    const listens = await web3.eth.net.isListening()
    console.log(listens);
  }

  isListening();
  ```

  ```javascript ethers.js theme={"system"}
  const ethers = require('ethers');
  const NODE_URL = "CHAINSTACK_NODE_URL";
  const provider = new ethers.JsonRpcProvider(NODE_URL);

  const isListening = async () => {
    const listen = await provider.send("net_listening");
    console.log(listen);
  }

  isListening()
  ```

  ```python web3.py theme={"system"}
  from web3 import Web3  
  node_url = "CHAINSTACK_NODE_URL"
  web3 = Web3.HTTPProvider(node_url)

  is_listening = web3.provider.make_request('net_listening', [])
  print(is_listening)
  ```
</CodeGroup>

## Use case

A method like `net_listening` can be used to monitor the network status of the Avalanche node a developer is connecting to. Imagine a blockchain explorer where users can search for transactions, addresses, and other information on the Avalanche blockchain. In order to provide accurate information to its users, the website needs to be able to monitor the current status of its connection.

Here is an example of this implementation using the web3.js library:

```javascript index.js theme={"system"}
const Web3 = require("web3");
const NODE_URL = "CHAINSTACK_NODE_URL";
const web3 = new Web3(NODE_URL);

// Create a function to monitor the node status and display information to users
async function monitorNetworkStatus() {
  try {
    // Check if the client is currently listening for network connections
    const isListening = await web3.eth.net.isListening();

    // Get the number of peers currently connected to the client
    const peerCount = await web3.eth.net.getPeerCount();

    // Log the network status information to the console
    console.log(`Network status: ${isListening ? 'Listening' : 'Not listening'} | Peers: ${peerCount}`);
  } catch (error) {
    // Handle any errors that might occur
    console.error(`Error monitoring network status: ${error}`);
  }
}

// Call the monitorNetworkStatus function at regular intervals to continuously monitor the network status
setInterval(monitorNetworkStatus, 5000); // Monitor every 5 seconds
```

The `monitorNetworkStatus` function defined in this code uses the `net_listening` method to check whether the Avalanche client is currently listening for network connections, and the net\_peerCount method to get the number of peers currently connected to the client.

The function logs this information to the console, which could be displayed to the user in a user-friendly format on the blockchain explorer website. By calling this function at regular intervals using the `setInterval` function, the website can continuously monitor the node's status and provide users with up-to-date information about the overall health of the node.


## OpenAPI

````yaml /openapi/avalanche_node_api/client_info/net_listening.json POST /8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc
openapi: 3.0.0
info:
  title: Chainstack Node API
  version: 1.0.0
  description: This is an API for interacting with a Chainstack node.
servers:
  - url: https://nd-418-459-126.p2pify.com
security: []
paths:
  /8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc:
    post:
      tags:
        - Update
      summary: net_listening
      operationId: listening
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                id:
                  type: integer
                  default: 1
                jsonrpc:
                  type: string
                  default: '2.0'
                method:
                  type: string
                  default: net_listening
                params:
                  type: array
                  default: []
      responses:
        '200':
          description: >-
            The boolean value that indicates whether or not a node is currently
            actively seeking peer connections.
          content:
            application/json:
              schema:
                type: object
                properties:
                  jsonrpc:
                    type: string
                  id:
                    type: integer
                  result:
                    type: string

````