eth_chainId - BSC

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

cURL

bashcurl --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"
}'

JavaScript (Axios)

javascriptconst 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));

Python

pythonimport 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}")

Rust

rustuse 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(())
}

Response Example

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

Response Parameters

ParameterTypeDescription
jsonrpcstringJSON-RPC version (2.0)
idstringRequest identifier
resultstringChain 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 CodeDescription
-32603Internal error - node processing issues
-32000Server error - RPC endpoint unavailable

SDK Integration

Ethers.js

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('Chain ID:', network.chainId); // 56n for BSC Mainnet

Viem

javascriptimport { 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