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 --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"
}'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 theidsent 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?