net_version - Celo

This method returns the current network ID of the Celo node.

Parameters

  • None

Request Example

bashcurl -X POST https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/ \
-H "Content-Type: application/json" \
-d '{
  "jsonrpc": "2.0",
  "id": "getblock.io",
  "method": "net_version",
  "params": []
}'
javascriptconst axios = require('axios');

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

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

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

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

payload = {
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "method": "net_version",
    "params": []
}

response = requests.post(url, headers={"Content-Type": "application/json"}, json=payload)
print(response.json())

Response Example

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

Response Definition

FieldTypeDescription
resultstringNetwork ID as a decimal string

Use Cases

  • Verify connection to correct network
  • Distinguish mainnet from testnet
  • Network detection in multi-chain apps

Error Handling

Error CodeDescription
-32603Internal error

SDK Integration

javascriptconst { ethers } = require('ethers');

const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

const network = await provider.getNetwork();
console.log('Network ID:', network.chainId.toString());
javascriptconst { newKit } = require('@celo/contractkit');

const kit = newKit('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

const networkId = await kit.web3.eth.net.getId();
console.log('Network ID:', networkId);