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

net_version - Optimism

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

This method returns the network ID as a decimal string. For Optimism Mainnet, this is '10'. The network ID identifies the network the node is connected to. On Optimism, the network ID equals the chain ID.

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_version",
    "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_version',
    params: [],
    id: 'getblock.io'
};

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

Response

A successful response returns the following:

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

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: The network ID as a decimal string. '10' for Optimism Mainnet.

Use Case

The net_version method is commonly used for:

  • Network identification

  • Multi-network support

  • Configuration validation

Error Handling

Error Code
Description

-32603

Internal error

Web3 Integration

Last updated

Was this helpful?