Skip to content
Crypto News

Blockchain markets, protocols and regulation

Chain ID Hex vs Decimal: How the Formats Differ

Chain ID hex vs decimal format explained: both notations represent the same integer; use decimal in configs and 0x-prefixed hex in JSON-RPC and wallet calls.

The Crypto News Editors

Chain ID Hex vs Decimal: How the Formats Differ

A chain ID is the same integer whether you write it in decimal or hexadecimal; the tool you are using determines which notation to send. Base is 8453 in decimal and 0x2105 in hex. The 0x prefix marks the value as hexadecimal.

Decimal is common in network directories, explorers and development configs. In a directory such as Chainlist, the chain ID appears as a decimal value beside network details, while JSON-RPC responses and wallet RPC methods use hex strings. Entering 0x2105 into a field that expects decimal can produce an invalid or different ID, leading a wallet such as MetaMask to flag a chain ID mismatch.

Use the notation each tool expects

Use decimal when a tool labels its field as a chain ID number, as many Hardhat and Foundry configs and explorers do. Use 0x-prefixed hex for JSON-RPC quantities and wallet RPC methods. These conventions describe the same network identifier, but the formats are not interchangeable as text.

The JSON-RPC method eth_chainId returns a hexadecimal quantity. Ethereum mainnet returns 0x1. The wallet method wallet_addEthereumChain also expects its chainId parameter in hex, such as "0x2105" for Base. Send the canonical form without leading zeros: "0x1", not "0x01", and do not send the decimal number 1 in place of the hex string. A wallet can reject a value with leading zeros even though it may look like the same integer.

Common decimal and hexadecimal pairs are:

  • 1 = 0x1
  • 56 = 0x38
  • 137 = 0x89
  • 8453 = 0x2105
  • 42161 = 0xa4b1

To convert in JavaScript, use parseInt('0x2105', 16) to get 8453, or (8453).toString(16) to get "2105" and add the 0x prefix. Keep the value as a number in a decimal config; use the prefixed string where a JSON-RPC method expects a hex quantity.

MetaMask shows the value in decimal

MetaMask can display a chain ID in decimal even though the wallet RPC request uses hex; it is showing the same integer in a different notation. For Base, 8453 in a display and 0x2105 in a request refer to the same chain. Compare the converted values rather than treating the differing strings as different IDs.

The chain ID is also distinct from the transaction's v value. In legacy EIP-155 signatures, v incorporates the chain ID along with the signature’s recovery parity, so it is not simply another way to write the chain ID. Read the chain ID from the network configuration or eth_chainId, and interpret v as part of the transaction signature.

Related

Why does MetaMask show the chain ID in decimal?

MetaMask shows the chain ID in decimal for readability. Convert that integer to 0x-prefixed hex when a wallet RPC method requires a hexadecimal chain ID.

How is the chain ID encoded in a transaction's v value?

For a legacy EIP-155 signature, v combines the chain ID and recovery parity. It therefore carries chain information but is not the chain ID field itself.

Before adding a network or comparing a config with an RPC response, convert both values to the same integer and send the notation the specific field requires.