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
ZetaChain Chain ID
The ZetaChain 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 ZetaChain mainnet
Implementation Examples
- cURL
- JavaScript
- Python
curl -X POST https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_chainId",
"params": [],
"id": 1
}'
// Using fetch
const response = await fetch('https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_chainId',
params: [],
id: 1,
}),
});
const data = await response.json();
const chainId = parseInt(data.result, 16);
console.log('Chain ID:', chainId); // 7000
// Using ethers.js
import { ethers } from 'ethers';
const provider = new ethers.JsonRpcProvider('https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY');
const network = await provider.getNetwork();
console.log('Network chain ID:', network.chainId);
// Using web3.js
import Web3 from 'web3';
const web3 = new Web3('https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY');
const chainId = await web3.eth.getChainId();
console.log('ZetaChain chain ID:', chainId);
// Cross-chain aware implementation
class OmnichainProvider {
constructor() {
this.providers = new Map();
this.chainIds = new Map();
}
async addChain(name, rpcUrl) {
const provider = new ethers.JsonRpcProvider(rpcUrl);
const chainId = Number((await provider.getNetwork()).chainId);
this.providers.set(name, provider);
this.chainIds.set(name, chainId);
if (chainId === 7000) {
console.log('Connected to ZetaChain omnichain network');
}
return chainId;
}
async verifyZetaChain() {
const zetaProvider = this.providers.get('zetachain');
if (!zetaProvider) {
throw new Error('ZetaChain provider not configured');
}
const chainId = await zetaProvider.send('eth_chainId', []);
if (parseInt(chainId, 16) !== 7000) {
throw new Error('Not connected to ZetaChain mainnet');
}
return true;
}
}
import requests
import json
# Using requests
url = 'https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY'
headers = {'Content-Type': 'application/json'}
payload = {
'jsonrpc': '2.0',
'method': 'eth_chainId',
'params': [],
'id': 1
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
result = response.json()
chain_id = int(result['result'], 16)
print(f'Chain ID: {chain_id}') # 7000
# Using web3.py
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY'))
chain_id = w3.eth.chain_id
print(f'ZetaChain network chain ID: {chain_id}')
# Multi-chain verification
def verify_omnichain_setup():
chains = {
'zetachain': 'https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY',
'ethereum': 'https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY',
'bsc': 'https://bsc-dataseed.binance.org/'
}
chain_ids = {}
for name, rpc_url in chains.items():
w3 = Web3(Web3.HTTPProvider(rpc_url))
if w3.is_connected():
chain_ids[name] = w3.eth.chain_id
print(f'{name}: Chain ID {chain_ids[name]}')
# Verify ZetaChain is configured
if chain_ids.get('zetachain') != 7000:
raise ValueError('ZetaChain not properly configured')
return chain_ids
Example Response
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x1b58"
}
Network Information
ZetaChain Networks
Network | Chain ID (Hex) | Chain ID (Decimal) | Description |
---|---|---|---|
Mainnet | 0x1b58 | 7000 | ZetaChain main network |
Athens-3 Testnet | 0x1b59 | 7001 | ZetaChain test network |
Connected Chains
ZetaChain connects to multiple blockchain networks:
Chain | Chain ID | Connection Type |
---|---|---|
Ethereum | 1 | Native Integration |
Bitcoin | N/A | TSS Bridge |
BSC | 56 | Native Integration |
Polygon | 137 | Native Integration |
Avalanche | 43114 | Native Integration |
Common Use Cases
1. Network Verification
async function verifyNetwork() {
const expectedChainId = 7000; // ZetaChain 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 ZetaChain omnichain network');
return true;
}
2. Omnichain dApp Configuration
const OMNICHAIN_CONFIG = {
7000: {
name: 'ZetaChain Mainnet',
symbol: 'ZETA',
rpcUrl: 'https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY',
explorer: 'https://explorer.zetachain.com',
connectorAddress: '0x239e96c8f17C85c30100AC26F635Ea15f23E9c67',
supportedChains: [1, 56, 137, 43114] // ETH, BSC, Polygon, Avalanche
},
7001: {
name: 'ZetaChain Athens-3 Testnet',
symbol: 'aZETA',
rpcUrl: 'https://zetachain-athens-3.g.allthatnode.com/archive/evm',
explorer: 'https://athens.explorer.zetachain.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),
// ZetaChain specific: cross-chain metadata
zetaParams: tx.crossChain ? {
destinationChainId: tx.destinationChainId,
destinationGasLimit: tx.destinationGasLimit
} : null
});
return signedTx;
}
4. Wallet Network Switch
async function switchToZetaChain() {
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: 'ZetaChain Mainnet',
nativeCurrency: {
name: 'ZETA',
symbol: 'ZETA',
decimals: 18
},
rpcUrls: ['https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY'],
blockExplorerUrls: ['https://explorer.zetachain.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 ZetaChain
if (chainId === 7000) {
this.zetaProvider = provider;
console.log('ZetaChain omnichain hub initialized');
}
}
async routeCrossChainMessage(sourceChainId, destChainId, message) {
// Verify ZetaChain is available for routing
if (!this.zetaProvider) {
throw new Error('ZetaChain hub not initialized');
}
const zetaChainId = await this.zetaProvider.send('eth_chainId', []);
if (parseInt(zetaChainId, 16) !== 7000) {
throw new Error('Invalid ZetaChain connection');
}
// Route through ZetaChain
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
// ZetaChain uses chain IDs to route cross-chain messages
async function sendCrossChainMessage(destChainId, message) {
const zetaChainId = await provider.send('eth_chainId', []);
if (parseInt(zetaChainId, 16) !== 7000) {
throw new Error('Must be connected to ZetaChain');
}
const crossChainTx = {
to: CONNECTOR_CONTRACT,
data: encodeCrossChainCall(destChainId, message),
value: calculateCrossChainFee(destChainId)
};
return await signer.sendTransaction(crossChainTx);
}
Chain ID Mapping
const CHAIN_ID_MAP = {
// ZetaChain
7000: { name: 'ZetaChain', 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
- Always verify chain ID before sending transactions
- Cache chain ID to reduce RPC calls
- Handle network switches gracefully
- Use chain ID for transaction replay protection
- Validate against expected network for omnichain operations
Error Codes
Code | Message | Description |
---|---|---|
-32600 | Invalid Request | The JSON sent is not valid |
-32601 | Method not found | Method doesn't exist |
-32602 | Invalid params | Invalid parameters |
-32603 | Internal error | Internal JSON-RPC error |
Related Methods
- net_version - Get network version
- eth_getBlockByNumber - Get block information
- eth_sendRawTransaction - Send signed transaction
- eth_accounts - List available accounts