eth_chainId - Base
Example code for the eth_chainId JSON-RPC method. Complete guide on how to use eth_chainId JSON-RPC in GetBlock Web3 documentation.
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 --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_chainId",
"params": [],
"id": "getblock.io"
}'const axios = require('axios');
const response = await axios.post('https://go.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));import requests
response = requests.post(
'https://go.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}')Response
{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": "0x2105"
}Response Parameters
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
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
-32603
Internal error
Node internal failure
-32600
Invalid request
Malformed JSON-RPC request
Web3 Integration
Last updated
Was this helpful?