eth_chainId - Base
The eth_chainId method returns the chain ID of the Base network. This value is essential for EIP-155 transaction signing to prevent replay attacks across different networks. Base mainnet uses chain ID 8453.
Parameters
- None
Request
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"
}'axios.js
javascriptconst axios = require('axios');
const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
jsonrpc: '2.0',
method: 'eth_chainId',
params: [],
id: 'getblock.io'
}, {
headers: { 'Content-Type': 'application/json' }
});
console.log('Chain ID:', parseInt(response.data.result, 16));requests.py
pythonimport requests
response = requests.post(
'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
headers={'Content-Type': 'application/json'},
json={
'jsonrpc': '2.0',
'method': 'eth_chainId',
'params': [],
'id': 'getblock.io'
}
)
result = response.json()
chain_id = int(result['result'], 16)
print(f'Chain ID: {chain_id}')main.rs
rustuse reqwest::Client;
use serde_json::{json, Value};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let response = client
.post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
.header("Content-Type", "application/json")
.json(&json!({
"jsonrpc": "2.0",
"method": "eth_chainId",
"params": [],
"id": "getblock.io"
}))
.send()
.await?
.json::<Value>()
.await?;
println!("Chain ID: {}", response["result"]);
Ok(())
}Response
response.json
json{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": "0x2105"
}Response Parameters
| Parameter | Type | Description |
|---|---|---|
| jsonrpc | string | JSON-RPC protocol version ("2.0") |
| id | string | Request identifier matching the request |
| result | string | Hexadecimal chain ID (0x2105 = 8453 for Base mainnet) |
Chain ID Reference
| Network | Chain ID (Decimal) | Chain ID (Hex) |
|---|---|---|
| Base Mainnet | 8453 | 0x2105 |
| Base Sepolia | 84532 | 0x14A34 |
Use Cases
- Network Verification: Confirm connection to the correct network before transactions
- Transaction Signing: Include chain ID in EIP-155 signatures to prevent replay attacks
- Multi-Chain Applications: Route transactions to appropriate networks
- Wallet Integration: Verify network configuration matches expected chain
- Smart Contract Deployment: Ensure deployment targets the intended network
Error Handling
| Error Code | Message | Description |
|---|---|---|
| -32603 | Internal error | Node internal failure |
| -32600 | Invalid request | Malformed JSON-RPC request |
Web3 Integration
ethers.js
javascriptconst { ethers } = require('ethers');
const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');
async function getChainId() {
const network = await provider.getNetwork();
console.log('Chain ID:', network.chainId);
console.log('Network Name:', network.name);
return network.chainId;
}
getChainId();viem.js
javascriptimport { createPublicClient, http } from 'viem';
import { base } from 'viem/chains';
const client = createPublicClient({
chain: base,
transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});
async function getChainId() {
const chainId = await client.getChainId();
console.log('Chain ID:', chainId);
return chainId;
}
getChainId();