⚠️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

TRON Chain ID

The TRON mainnet chain ID is: 0x2b67540c (728126428 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: 0x2b67540c for TRON mainnet

Implementation Examples

curl -X POST https://api-tron-jsonrpc.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": "0x2b67540c"
}

Network Information

TRON Networks

NetworkChain ID (Hex)Chain ID (Decimal)Description
Mainnet0x2b67540c728126428TRON main network
Testnet (Shasta)0x94a9059e2494104990TRON test network
Testnet (Nile)0xcd8690dc3448148188TRON test network

Common Use Cases

1. Network Verification

async function verifyNetwork() {
const expectedChainId = 728126428; // TRON 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 TRON mainnet');
return true;
}

2. Multi-Chain dApp Support

const NETWORK_CONFIG = {
728126428: {
name: 'TRON Mainnet',
symbol: 'TRX',
rpcUrl: 'https://api-tron-jsonrpc.dwellir.com/YOUR_API_KEY',
explorer: 'https://tronscan.org'
},
2494104990: {
name: 'TRON Shasta Testnet',
symbol: 'TRX',
rpcUrl: 'https://api.shasta.trongrid.io/jsonrpc',
explorer: 'https://shasta.tronscan.org'
}
};

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

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

return config;
}

3. EIP-155 Transaction Signing

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

// Include chain ID for replay protection
const signedTx = await wallet.signTransaction({
...tx,
chainId: parseInt(chainId, 16)
});

return signedTx;
}

4. Wallet Network Switch

async function switchToTRON() {
try {
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x2b67540c' }],
});
} catch (switchError) {
// Network not added to wallet
if (switchError.code === 4902) {
await window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: '0x2b67540c',
chainName: 'TRON Mainnet',
nativeCurrency: {
name: 'TRON',
symbol: 'TRX',
decimals: 6
},
rpcUrls: ['https://api-tron-jsonrpc.dwellir.com/YOUR_API_KEY'],
blockExplorerUrls: ['https://tronscan.org']
}],
});
}
}
}

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

Error Codes

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