For the complete documentation index, see llms.txt. This page is also available as Markdown.

net_listening - Optimism

Example code for the net_listening json-rpc method. Сomplete guide on how to use net_listening json-rpc in GetBlock.io Web3 documentation.

This method returns a boolean indicating if the client is actively listening for network connections. This is useful for checking if the node is operational and accepting peer connections.

Parameters

  • None

Request Sample

cURL
curl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "net_listening",
    "params": [],
    "id": "getblock.io"
}'
request.js
const axios = require('axios');

const url = 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/';

const payload = {
    jsonrpc: '2.0',
    method: 'net_listening',
    params: [],
    id: 'getblock.io'
};

axios.post(url, payload, {
    headers: { 'Content-Type': 'application/json' }
})
.then(response => console.log('Listening:', response.data.result))
.catch(error => console.error(error));

Response

A successful response returns the following:

{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": true
}

Response Parameters

  • id: A unique request identifier, matching the id sent in the request body.

  • jsonrpc: Specifies the use of JSON-RPC version 2.0.

  • result: Boolean indicating if the node is listening for connections.

Error Handling

Error Code
Description

-32603

Internal error

Web3 Integration

Last updated

Was this helpful?