Docs
Docs
Home
Getting Started
Agent Tooling
CLI
Supported Chains
Acala
Aptos
Arbitrum
Arc
Asset Hub
Astar
Avalanche
Base
Berachain
Bifrost
Binance Smart Chain
Bittensor
Blast
Boba Network
Bridge Hub
Celo
Centrifuge
Chiliz
Cronos
Enjin
Ethereum
Etherlink
Flow EVM Gateway
Gnosis
Hydration
Hyperliquid
Immutable
Ink
IoTeX
Kusama
Linea
LISK
Manta Atlantic
Manta Pacific
Mantle
MegaETH
Monad
Movement
Neuroweb
opBNB
Optimism
Plasma
Polkadot
Polygon
Pulsechain
Robinhood
Ronin
Scroll
Sonic
Starknet
Taiko
Tempo
Sui
TRON
Unichain
Viction
World Chain
XDC Network
XX Network
Zetachain
zkSync Era
Zora
Supported ChainsPlasmaJSON-RPC APINetwork Methods

eth_chainId - Plasma RPC Method

Get the chain ID for Plasma. Essential for transaction signing and network verification.

Plasma RPC endpoint: endpoint URLs, plans and pricing.

Returns the chain ID used for transaction signing on Plasma.

Why Plasma? Build on an EVM Layer 1 for stablecoin payments with PlasmaBFT consensus and Reth execution with 1 second blocks, XPL gas, full EVM JSON-RPC, and debug plus txpool on Dwellir.

When to Use This Method

eth_chainId is essential for payment app developers, wallet teams, and teams shipping Solidity contracts for dollar transfers:

  • EIP-155 Transaction Signing -- Include the chain ID in transaction signatures to prevent replay attacks across different networks
  • Multi-Chain Application Routing -- Detect which network the RPC endpoint serves and configure application logic accordingly
  • Wallet Integration -- Verify users are connected to the expected network before prompting transaction approval
  • Cross-Chain Security -- Validate chain identity before bridging assets or relaying messages on stablecoin transfers, payment apps, and wallets that need 1 second confirmation

Common Use Cases

1. Multi-Network Connection Guard

Reject connections to unexpected networks before any transaction is sent:

JavaScript
import { JsonRpcProvider, BrowserProvider } from 'ethers';

async function guardNetwork(provider, allowedChainIds) {
  const network = await provider.getNetwork();
  const chainId = Number(network.chainId);
  
  if (!allowedChainIds.includes(chainId)) {
    throw new Error(
      `Wrong network: connected to chain ${chainId}, expected one of [${allowedChainIds}]`
    );
  }
  
  console.log(`Connected to chain ${chainId}`);
  return chainId;
}

// Example: only allow Ethereum mainnet (1) and Arbitrum (42161)
await guardNetwork(provider, [1, 42161]);

2. Wallet Network Switcher

Detect the current chain and prompt wallet to switch if needed:

JavaScript
async function ensureCorrectChain(walletProvider, targetChainId, chainParams) {
  const currentChainId = await walletProvider.send('eth_chainId', []);
  const currentId = parseInt(currentChainId, 16);
  
  if (currentId !== targetChainId) {
    try {
      await walletProvider.send('wallet_switchEthereumChain', [
        { chainId: '0x' + targetChainId.toString(16) }
      ]);
    } catch (switchError) {
      // Chain not added to wallet -- add it
      if (switchError.code === 4902) {
        await walletProvider.send('wallet_addEthereumChain', [chainParams]);
      } else {
        throw switchError;
      }
    }
    
    console.log(`Switched to chain ${targetChainId}`);
  } else {
    console.log(`Already on chain ${targetChainId}`);
  }
  
  return targetChainId;
}

3. Chain-Aware Configuration Loader

Dynamically load chain-specific contract addresses and settings:

Python
from web3 import Web3

def load_chain_config(rpc_url):
    w3 = Web3(Web3.HTTPProvider(rpc_url))
    chain_id = w3.eth.chain_id
    
    configs = {
        1: {
            'name': 'Ethereum Mainnet',
            'uniswap_router': '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',
            'explorer': 'https://etherscan.io',
            'native_symbol': 'ETH'
        },
        137: {
            'name': 'Polygon',
            'uniswap_router': '0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff',
            'explorer': 'https://polygonscan.com',
            'native_symbol': 'MATIC'
        },
        42161: {
            'name': 'Arbitrum One',
            'uniswap_router': '0xE592427A0AEce92De3Edee1F18E0157C05861564',
            'explorer': 'https://arbiscan.io',
            'native_symbol': 'ETH'
        }
    }
    
    if chain_id not in configs:
        raise ValueError(f'Unsupported chain ID: {chain_id}')
    
    config = configs[chain_id]
    print(f'Loaded config for {config["name"]} (chain {chain_id})')
    return {'chain_id': chain_id, **config}

Best Practices

  • Use eth_chainId (not net_version) for EIP-155 transaction signing -- chain ID is the canonical signing value
  • Cache the chain ID at application startup -- it does not change during a session
  • For browser wallet dApps, use wallet_switchEthereumChain and wallet_addEthereumChain to guide users to the correct network
  • Some L2 chains share the same chain ID as their L1 -- always combine chain ID checks with additional endpoint verification
  • Return value is a hex-encoded integer -- parse with parseInt(result, 16) before using
JSON-RPC request
{
  "jsonrpc": "2.0",
  "method": "eth_chainId",
  "params": [],
  "id": 1
}

Code Examples

Related Methods

  • net_version - Get network version
  • eth_syncing - Check sync status

debug_traceTransaction

Trace a transaction execution on Plasma. Requires archive node for debugging stablecoin transfers, payment apps, and wallets that need 1 second confirmation.

eth_syncing

Check the sync status of your Plasma node. Returns sync progress or false when fully synced - essential for node health monitoring and dApp reliability.

On this page

When to Use This MethodCommon Use Cases1. Multi-Network Connection Guard2. Wallet Network Switcher3. Chain-Aware Configuration LoaderBest PracticesCode ExamplesRelated Methods