⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

eth_chainId

Returns the chain ID of the current network. For Linea mainnet, this returns 0xe708 (59144 in decimal).

Parameters

None

Returns

QUANTITY - The chain ID as a hexadecimal string.

Request Example

{
"jsonrpc": "2.0",
"method": "eth_chainId",
"params": [],
"id": 1
}

Response Example

{
"jsonrpc": "2.0",
"id": 1,
"result": "0xe708"
}

Implementation Examples

import { JsonRpcProvider } from 'ethers';

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

// Get chain ID
async function getChainId() {
const chainId = await provider.getNetwork().then(n => n.chainId);

console.log('Chain ID (decimal):', chainId);
console.log('Chain ID (hex):', '0x' + chainId.toString(16));

// Verify it's Linea
if (chainId === 59144n) {
console.log('Connected to Linea mainnet');
}

return chainId;
}

// Verify network before transactions
async function verifyNetwork() {
const chainId = await provider.send('eth_chainId', []);
const expectedChainId = '0xe708'; // Linea mainnet

if (chainId !== expectedChainId) {
throw new Error(`Wrong network! Expected Linea (${expectedChainId}), got ${chainId}`);
}

return true;
}

Network Information

NetworkChain ID (Decimal)Chain ID (Hex)
Linea Mainnet591440xe708

Common Use Cases

1. Multi-Network Support

// Handle multiple networks
async function getNetworkConfig() {
const chainId = await provider.send('eth_chainId', []);

const networks = {
'0x1': { name: 'Ethereum Mainnet', explorer: 'https://etherscan.io' },
'0xe708': { name: 'Linea Mainnet', explorer: 'https://lineascan.build' },
'0x89': { name: 'Polygon', explorer: 'https://polygonscan.com' }
};

const network = networks[chainId] || { name: 'Unknown', explorer: null };

return {
chainId: chainId,
decimal: parseInt(chainId, 16),
...network
};
}

2. Wallet Connection Validation

// Validate wallet is on correct network
async function validateWalletNetwork(expectedChainId = 59144) {
if (typeof window.ethereum === 'undefined') {
throw new Error('No wallet detected');
}

const chainId = await window.ethereum.request({
method: 'eth_chainId'
});

const currentChainId = parseInt(chainId, 16);

if (currentChainId !== expectedChainId) {
// Request network switch
try {
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0xe708' }]
});
} catch (switchError) {
// Network not added to wallet
if (switchError.code === 4902) {
await addLineaNetwork();
}
}
}
}

// Add Linea network to wallet
async function addLineaNetwork() {
await window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: '0xe708',
chainName: 'Linea',
nativeCurrency: {
name: 'ETH',
symbol: 'ETH',
decimals: 18
},
rpcUrls: ['https://api-linea-mainnet-archive.n.dwellir.com/YOUR_API_KEY'],
blockExplorerUrls: ['https://lineascan.build']
}]
});
}

Need help? Contact our support team or check the Linea documentation.