> For the complete documentation index, see [llms.txt](https://docs.getblock.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.getblock.io/api-reference/bnb-smart-chain-bsc/eth_chainid-bsc.md).

# eth\_chainId - BSC

Example code for the eth\_chainId JSON RPC method. Сomplete guide on how to use eth\_chainId JSON RPC in GetBlock Web3 documentation.

This method returns the chain ID of the BNB Smart Chain network. The chain ID is used to prevent replay attacks across different EVM networks. BSC Mainnet uses chain ID 56, while the Testnet uses 97. This value is essential for transaction signing and network identification.

## Parameters

* None

## Request Example

{% tabs %}
{% tab title="CURL" %}
{% code title="cURL" %}

```bash
curl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_chainId",
    "params": [],
    "id": "getblock.io"
}'
```

{% endcode %}
{% endtab %}

{% tab title="Axios" %}
{% code title="JavaScript (Axios)" %}

```javascript
const axios = require('axios');

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

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

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

{% endcode %}
{% endtab %}

{% tab title="Request" %}
{% code title="Python" overflow="wrap" %}

```python
import requests
import json

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

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

response = requests.post(url, headers={"Content-Type": "application/json"}, json=payload)
chain_id = int(response.json()["result"], 16)
print(f"Chain ID: {chain_id}")
```

{% endcode %}
{% endtab %}

{% tab title="Rust" %}
{% code title="Rust" %}

```rust
use reqwest::Client;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    
    let payload = json!({
        "jsonrpc": "2.0",
        "method": "eth_chainId",
        "params": [],
        "id": "getblock.io"
    });

    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&payload)
        .send()
        .await?;

    let result: serde_json::Value = response.json().await?;
    println!("{:#?}", result);
    
    Ok(())
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Response Example

```json
{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0x38"
}
```

## Response Parameters

| Parameter | Type   | Description                                 |
| --------- | ------ | ------------------------------------------- |
| jsonrpc   | string | JSON-RPC version (2.0)                      |
| id        | string | Request identifier                          |
| result    | string | Chain ID in hex (0x38 = 56 for BSC Mainnet) |

## Use Cases

* Verify connection to correct network
* Include in transaction signing for replay protection
* Validate RPC endpoint configuration
* Network detection in multi-chain applications
* Wallet network switching

## Error Handling

| Error Code | Description                             |
| ---------- | --------------------------------------- |
| -32603     | Internal error - node processing issues |
| -32000     | Server error - RPC endpoint unavailable |

## SDK Integration

{% tabs %}
{% tab title="Ethers.js" %}
{% code title="Ethers.js" %}

```javascript
const { ethers } = require('ethers');

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

const network = await provider.getNetwork();
console.log('Chain ID:', network.chainId); // 56n for BSC Mainnet
```

{% endcode %}
{% endtab %}

{% tab title="Viem" %}
{% code title="Viem" %}

```javascript
import { createPublicClient, http } from 'viem';
import { bsc } from 'viem/chains';

const client = createPublicClient({
    chain: bsc,
    transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});

const chainId = await client.getChainId();
console.log('Chain ID:', chainId); // 56 for BSC Mainnet
```

{% endcode %}
{% endtab %}
{% endtabs %}
