# net_version - Bittensor RPC Method

Returns the current network ID on Bittensor as a decimal string. The network ID identifies which network the node is connected to.

> **Why Bittensor?** Build on the decentralized machine intelligence network built around subnets, TAO staking, and validator-miner coordination with Yuma Consensus, subnet-based specialization, dual Substrate and EVM surfaces, and onchain incentive coordination.

## When to Use This Method

`net_version` is essential for AI/ML developers, subnet operators, and teams building decentralized machine learning applications:

- **Endpoint Identification** - Confirm your application is connected to the expected Bittensor 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

## Request Parameters

This method accepts no parameters.

## Request Example

```json
{
  "jsonrpc": "2.0",
  "method": "net_version",
  "params": [],
  "id": 1
}
```

## Response Fields

- `result` (`String, required`): The current network ID as a decimal string (e.g., "1" for Ethereum mainnet, "5" for Goerli)

## Successful Response

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "1"
}
```

## Error Responses

### Error Response

- Code: `-32601`

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32601,
    "message": "The method net_version does not exist/is not available"
  }
}
```

## Code Examples

cURL
JavaScript
Python
Go

```bash
curl -X POST https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "net_version",
    "params": [],
    "id": 1
  }'
```

```javascript
import { JsonRpcProvider } from 'ethers';

const provider = new JsonRpcProvider('https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY');

const networkId = await provider.send('net_version', []);
console.log('Bittensor network ID:', networkId);

// Using fetch
const response = await fetch('https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    method: 'net_version',
    params: [],
    id: 1
  })
});

const { result } = await response.json();
console.log('Network ID:', result);
```

```python
from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY'))

network_id = w3.net.version
print(f'Bittensor network ID: {network_id}')

# Using requests directly
import requests

response = requests.post(
    'https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY',
    json={
        'jsonrpc': '2.0',
        'method': 'net_version',
        'params': [],
        'id': 1
    }
)
result = response.json()['result']
print(f'Network ID: {result}')
```

```go
package main

import (
    "context"
    "fmt"
    "log"

    "github.com/ethereum/go-ethereum/rpc"
)

func main() {
    client, err := rpc.Dial("https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY")
    if err != nil {
        log.Fatal(err)
    }

    var networkId string
    err = client.CallContext(context.Background(), &networkId, "net_version")
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Bittensor network ID: %s\n", networkId)
}
```

## Common Use Cases

### 1. Multi-Chain Connection Validator

Verify your application connects to the expected network before processing any transactions:

```javascript
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:

```javascript
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:

```python
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_chainId` for transaction signing (EIP-155 replay protection) -- `net_version` is 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_chainId` for 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

## Related Methods

- [`eth_chainId`](https://www.dwellir.com/docs/bittensor/eth_chainId) - Get the EIP-155 chain ID (preferred for transaction signing)
- [`net_listening`](https://www.dwellir.com/docs/bittensor/net_listening) - Check whether the client reports peer-listening state
- [`net_peerCount`](https://www.dwellir.com/docs/bittensor/net_peerCount) - Get number of connected peers
- [`eth_syncing`](https://www.dwellir.com/docs/bittensor/eth_syncing) - Check node sync progress
