⚠️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 used for signing replay-protected transactions.

When to Use This Method

Use eth_chainId to:

  • Network Verification - Ensure connected to the correct network
  • Transaction Signing - Include chain ID for EIP-155 replay protection
  • Multi-Chain Support - Switch between networks in dApps
  • Configuration Validation - Verify network settings
  • Cross-Chain Routing - Identify source chain for omnichain operations

xdc Chain ID

The xdc mainnet chain ID is: 0x1b58 (7000 in decimal)

Parameters

This method accepts no parameters.

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

Returns

QUANTITY - The chain ID as a hexadecimal string.

  • Type: Hexadecimal string
  • Format: 0x prefixed
  • Value: 0x1b58 for xdc mainnet

Implementation Examples

curl -X POST https://api-xdc-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_chainId",
"params": [],
"id": 1
}'

Example Response

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

Network Information

xdc Networks

NetworkChain ID (Hex)Chain ID (Decimal)Description
Mainnet0x1b587000xdc main network
Athens-3 Testnet0x1b597001xdc test network

Connected Chains

xdc connects to multiple blockchain networks:

ChainChain IDConnection Type
Ethereum1Native Integration
BitcoinN/ATSS Bridge
BSC56Native Integration
Polygon137Native Integration
Avalanche43114Native Integration

Common Use Cases

1. Network Verification

async function verifyNetwork() {
const expectedChainId = 7000; // xdc mainnet
const chainId = await provider.send('eth_chainId', []);
const actualChainId = parseInt(chainId, 16);

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

console.log('Connected to xdc omnichain network');
return true;
}

2. Omnichain dApp Configuration

const OMNICHAIN_CONFIG = {
7000: {
name: 'xdc Mainnet',
symbol: 'ZETA',
rpcUrl: 'https://api-xdc-mainnet.n.dwellir.com/YOUR_API_KEY',
explorer: 'https://explorer.xdc.com',
connectorAddress: '0x239e96c8f17C85c30100AC26F635Ea15f23E9c67',
supportedChains: [1, 56, 137, 43114] // ETH, BSC, Polygon, Avalanche
},
7001: {
name: 'xdc Athens-3 Testnet',
symbol: 'aZETA',
rpcUrl: 'https://xdc-athens-3.g.allthatnode.com/archive/evm',
explorer: 'https://athens.explorer.xdc.com',
connectorAddress: '0x0000c9ec4042283e8139c74f4c64bcd1e0b9b54f',
supportedChains: [5, 97, 80001, 43113] // Test networks
}
};

async function getOmnichainConfig() {
const chainId = await web3.eth.getChainId();
const config = OMNICHAIN_CONFIG[chainId];

if (!config) {
throw new Error(`Unsupported network: ${chainId}`);
}

// Initialize cross-chain connectors
for (const supportedChain of config.supportedChains) {
console.log(`Supported cross-chain to: ${supportedChain}`);
}

return config;
}

3. EIP-155 Transaction Signing

async function signOmnichainTransaction(tx) {
const chainId = await provider.send('eth_chainId', []);

// Include chain ID for replay protection
const signedTx = await wallet.signTransaction({
...tx,
chainId: parseInt(chainId, 16),
// xdc specific: cross-chain metadata
zetaParams: tx.crossChain ? {
destinationChainId: tx.destinationChainId,
destinationGasLimit: tx.destinationGasLimit
} : null
});

return signedTx;
}

4. Wallet Network Switch

async function switchToxdc() {
try {
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x1b58' }],
});
} catch (switchError) {
// Network not added to wallet
if (switchError.code === 4902) {
await window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: '0x1b58',
chainName: 'xdc Mainnet',
nativeCurrency: {
name: 'ZETA',
symbol: 'ZETA',
decimals: 18
},
rpcUrls: ['https://api-xdc-mainnet.n.dwellir.com/YOUR_API_KEY'],
blockExplorerUrls: ['https://explorer.xdc.com']
}],
});
}
}
}

5. Cross-Chain Transaction Router

class CrossChainRouter {
constructor() {
this.chainProviders = new Map();
}

async initializeChain(chainId, rpcUrl) {
const provider = new ethers.JsonRpcProvider(rpcUrl);
const network = await provider.getNetwork();

if (Number(network.chainId) !== chainId) {
throw new Error(`Chain ID mismatch: expected ${chainId}, got ${network.chainId}`);
}

this.chainProviders.set(chainId, provider);

// Special handling for xdc
if (chainId === 7000) {
this.zetaProvider = provider;
console.log('xdc omnichain hub initialized');
}
}

async routeCrossChainMessage(sourceChainId, destChainId, message) {
// Verify xdc is available for routing
if (!this.zetaProvider) {
throw new Error('xdc hub not initialized');
}

const xdcId = await this.zetaProvider.send('eth_chainId', []);
if (parseInt(xdcId, 16) !== 7000) {
throw new Error('Invalid xdc connection');
}

// Route through xdc
const connector = new ethers.Contract(
CONNECTOR_ADDRESS,
CONNECTOR_ABI,
this.zetaProvider
);

return await connector.send({
sourceChainId,
destChainId,
message,
gasLimit: 200000
});
}
}

Chain ID in Omnichain Context

Cross-Chain Identification

// xdc uses chain IDs to route cross-chain messages
async function sendCrossChainMessage(destChainId, message) {
const xdcId = await provider.send('eth_chainId', []);

if (parseInt(xdcId, 16) !== 7000) {
throw new Error('Must be connected to xdc');
}

const crossChainTx = {
to: CONNECTOR_CONTRACT,
data: encodeCrossChainCall(destChainId, message),
value: calculateCrossChainFee(destChainId)
};

return await signer.sendTransaction(crossChainTx);
}

Chain ID Mapping

const CHAIN_ID_MAP = {
// xdc
7000: { name: 'xdc', type: 'hub', symbol: 'ZETA' },

// Connected EVM Chains
1: { name: 'Ethereum', type: 'evm', symbol: 'ETH' },
56: { name: 'BSC', type: 'evm', symbol: 'BNB' },
137: { name: 'Polygon', type: 'evm', symbol: 'MATIC' },
43114: { name: 'Avalanche', type: 'evm', symbol: 'AVAX' },

// Bitcoin (special handling)
8332: { name: 'Bitcoin', type: 'bitcoin', symbol: 'BTC' }
};

function getChainInfo(chainId) {
return CHAIN_ID_MAP[chainId] || { name: 'Unknown', type: 'unknown' };
}

Best Practices

  1. Always verify chain ID before sending transactions
  2. Cache chain ID to reduce RPC calls
  3. Handle network switches gracefully
  4. Use chain ID for transaction replay protection
  5. Validate against expected network for omnichain operations

Error Codes

CodeMessageDescription
-32600Invalid RequestThe JSON sent is not valid
-32601Method not foundMethod doesn't exist
-32602Invalid paramsInvalid parameters
-32603Internal errorInternal JSON-RPC error