net_version - Celo RPC Method
Get the current network ID on Celo. Useful for endpoint identification and multi-network routing.
Returns the current network ID on Celo as a decimal string. The network ID identifies which network the node is connected to.
Why Celo? Build on the mobile-first L2 powering 500K+ daily active users and $2B+ monthly stablecoin volume with phone number-based addressing, sub-cent fees, 150+ country adoption, Nightfall privacy layer, and Opera browser integration.
When to Use This Method
net_version is essential for mobile payment developers, fintech builders, and teams targeting emerging markets:
- Endpoint Identification - Confirm your application is connected to the expected Celo network
- Multi-Chain App Routing - Dynamically detect which network an RPC endpoint serves and route logic accordingly
- Connection Validation - Perform a quick sanity check during node or provider initialization
Code Examples
Common Use Cases
1. Multi-Chain Connection Validator
Verify your application connects to the expected network before processing any transactions:
const EXPECTED_NETWORKS = {
'1': 'Ethereum Mainnet',
'137': 'Polygon',
'42161': 'Arbitrum One',
'10': 'Optimism',
};
async function validateNetwork(provider, expectedNetworkId) {
const networkId = await provider.send('net_version', []);
if (networkId !== expectedNetworkId) {
const actual = EXPECTED_NETWORKS[networkId] || `Unknown (${networkId})`;
const expected = EXPECTED_NETWORKS[expectedNetworkId] || expectedNetworkId;
throw new Error(`Wrong network: connected to ${actual}, expected ${expected}`);
}
console.log(`Connected to ${EXPECTED_NETWORKS[networkId]}`);
return networkId;
}2. Dynamic Chain Router
Route application logic based on the detected network:
async function createChainRouter(rpcUrl) {
const provider = new JsonRpcProvider(rpcUrl);
const networkId = await provider.send('net_version', []);
const config = {
'1': { explorer: 'https://etherscan.io', confirmations: 12 },
'137': { explorer: 'https://polygonscan.com', confirmations: 128 },
'42161': { explorer: 'https://arbiscan.io', confirmations: 1 },
};
if (!config[networkId]) {
throw new Error(`Unsupported network ID: ${networkId}`);
}
return { provider, networkId, ...config[networkId] };
}3. Network ID vs Chain ID Comparison
Compare net_version with eth_chainId when you need both endpoint identity and signing context:
from web3 import Web3
def verify_chain_identity(rpc_url):
w3 = Web3(Web3.HTTPProvider(rpc_url))
network_id = int(w3.net.version)
chain_id = w3.eth.chain_id
if network_id != chain_id:
print(f'Network ID ({network_id}) differs from chain ID ({chain_id})')
else:
print(f'Network and chain ID match: {chain_id}')
print('Use eth_chainId as the signing source of truth')
return {'network_id': network_id, 'chain_id': chain_id}Best Practices
- Use
eth_chainIdfor transaction signing (EIP-155 replay protection) --net_versionis for network identification only - Cache the network ID at startup -- it does not change during a session
- Some L2 and sidechain networks share the same network ID as their L1 -- always combine with
eth_chainIdfor unambiguous identification - For multi-chain dApps, maintain a mapping of network IDs to chain-specific contract addresses and RPC endpoints
- The
net_*namespace may be disabled on some node configurations -- handle the -32601 error gracefully
Error Handling
| Error Code | Description | Solution |
|---|---|---|
| -32601 | Method not found | The node may have the net namespace disabled -- check node startup flags |
| -32603 | Internal error | Node may be starting up -- retry after delay |
| -32005 | Rate limit exceeded | Reduce polling frequency or implement backoff |
Related Methods
eth_chainId- Get the EIP-155 chain ID (preferred for transaction signing)net_listening- Check whether the client reports peer-listening statenet_peerCount- Get number of connected peerseth_syncing- Check node sync progress
eth_syncing
Check the sync status of your Celo node. Returns sync progress or false when fully synced - essential for node health monitoring and dApp reliability.
net_listening
Check the legacy net_listening compatibility method on Celo. Public endpoints may return a boolean or an unsupported-method response depending on the client.