# net_listening - World Chain RPC Method

Checks whether the connected World Chain client reports that its P2P networking layer is listening for peers. Depending on the client behind the endpoint, this call may return `true`, `false`, or an unsupported-method error.

> **Why World Chain?** Build on the human-first Ethereum L2 powered by World ID with World ID integration for free gas and priority blockspace.

## When to Use This Method

`net_listening` is useful for World Chain developers building sybil-resistant applications:

- **P2P Diagnostics** - Check whether the connected client exposes peer-listening state at all
- **Client Capability Checks** - Distinguish between boolean responses and unsupported-method errors across different node clients
- **Peer-Network Troubleshooting** - Combine with `net_peerCount` and `eth_syncing` when investigating peer discovery or sync issues
- **Operational Audits** - Confirm what the endpoint reports before wiring it into monitoring or dashboards

## Best Practices

- Returns a boolean value only; combine with `net_peerCount` and `eth_syncing` for a comprehensive health check
- A `false` return indicates the node is not accepting network connections
- Some node clients may return an unsupported-method error instead of a boolean; handle both cases

## Request Parameters

This method accepts no parameters.

## Request Example

```json
{
  "jsonrpc": "2.0",
  "method": "net_listening",
  "params": [],
  "id": 1
}
```

## Response Fields

- `result` (`Boolean, required`): true if the client reports that it is listening for peers, false otherwise

## Successful Response

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}
```

## Code Examples

cURL
JavaScript
Python
Go

```bash
curl -X POST https://api-worldchain-mainnet.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "net_listening",
    "params": [],
    "id": 1
  }'
```

```javascript
import { JsonRpcProvider } from 'ethers';

const provider = new JsonRpcProvider('https://api-worldchain-mainnet.n.dwellir.com/YOUR_API_KEY');

try {
  const listening = await provider.send('net_listening', []);
  console.log('World Chain node listening:', listening);
} catch (error) {
  console.log('net_listening unsupported:', error.message);
}

// Using fetch
const response = await fetch('https://api-worldchain-mainnet.n.dwellir.com/YOUR_API_KEY', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    method: 'net_listening',
    params: [],
    id: 1
  })
});

const payload = await response.json();
if (payload.error) {
  console.log('net_listening unsupported:', payload.error.message);
} else {
  console.log('Listening:', payload.result);
}
```

```python
from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://api-worldchain-mainnet.n.dwellir.com/YOUR_API_KEY'))

try:
    listening = w3.net.listening
    print(f'World Chain node listening: {listening}')
except Exception as exc:
    print(f'net_listening unsupported: {exc}')

# Using requests directly
import requests

response = requests.post(
    'https://api-worldchain-mainnet.n.dwellir.com/YOUR_API_KEY',
    json={
        'jsonrpc': '2.0',
        'method': 'net_listening',
        'params': [],
        'id': 1
    }
)
payload = response.json()
if 'error' in payload:
    print(f"net_listening unsupported: {payload['error']['message']}")
else:
    print(f"Listening: {payload['result']}")
```

```go
package main

import (
    "context"
    "fmt"
    "log"

    "github.com/ethereum/go-ethereum/rpc"
)

func main() {
    client, err := rpc.Dial("https://api-worldchain-mainnet.n.dwellir.com/YOUR_API_KEY")
    if err != nil {
        log.Fatal(err)
    }

    var listening bool
    err = client.CallContext(context.Background(), &listening, "net_listening")
    if err != nil {
        log.Println("net_listening unsupported:", err)
        return
    }

    fmt.Printf("World Chain node listening: %t\n", listening)
}
```

## Common Use Cases

### 1. Capability-Aware Peer Diagnostic

Combine `net_listening` with other status methods, but treat unsupported responses as normal:

```javascript
async function getPeerDiagnostic(provider) {
  const [peerCountHex, syncing] = await Promise.all([
    provider.send('net_peerCount', []),
    provider.send('eth_syncing', [])
  ]);

  let listening = { supported: false };
  try {
    listening = { supported: true, value: await provider.send('net_listening', []) };
  } catch (error) {
    listening = { supported: false, message: error.message };
  }

  const peerCount = parseInt(peerCountHex, 16);
  return {
    listening,
    peerCount,
    synced: syncing === false
  };
}
```

### 2. Fallback-Friendly Check

```javascript
async function readListeningStatus(provider) {
  try {
    return { supported: true, value: await provider.send('net_listening', []) };
  } catch (error) {
    return { supported: false, message: error.message };
  }
}
```

### 3. Multi-Node Fleet Monitor

Check which endpoints expose `net_listening` and what they report:

```python
import requests
from concurrent.futures import ThreadPoolExecutor

def check_fleet_listening(endpoints):
    def check_node(endpoint):
        try:
            response = requests.post(
                endpoint,
                json={'jsonrpc': '2.0', 'method': 'net_listening', 'params': [], 'id': 1},
                timeout=5
            )
            payload = response.json()
            if 'error' in payload:
                return {'endpoint': endpoint, 'supported': False, 'error': payload['error']['message']}
            return {'endpoint': endpoint, 'supported': True, 'listening': payload.get('result', False)}
        except Exception as e:
            return {'endpoint': endpoint, 'supported': False, 'error': str(e)}

    with ThreadPoolExecutor(max_workers=10) as executor:
        results = list(executor.map(check_node, endpoints))

    supported = [r for r in results if r.get('supported')]
    unsupported = [r for r in results if not r.get('supported')]

    print(f'{len(supported)}/{len(results)} endpoints expose net_listening')
    for node in unsupported:
        print(f'  UNSUPPORTED: {node["endpoint"]} - {node.get("error", "not available")}')

    return results
```

## Related Methods

- [`net_peerCount`](https://www.dwellir.com/docs/world-chain/net_peerCount) - Get number of connected peers
- [`net_version`](https://www.dwellir.com/docs/world-chain/net_version) - Get the network ID
- [`eth_syncing`](https://www.dwellir.com/docs/world-chain/eth_syncing) - Check node sync progress
- [`web3_clientVersion`](https://www.dwellir.com/docs/world-chain/web3_clientVersion) - Get node client info
