TriportRPC

eth_chainId

Last updated:

`eth_chainId` returns the chain ID used for replay-protected transaction signing as introduced in [EIP-155](https://eips.ethereum.org/EIPS/eip-155). The value is encoded as a hexadecimal string; for Ethereum mainnet this is `0x1` (decimal `1`).

Use this method to confirm which network your RPC connection is pointed at before submitting transactions, and to derive the chain ID that must be included when signing EIP-155 transactions. It is the recommended way to detect the active network — prefer it over `net_version`, which returns the network ID as a decimal string and is not guaranteed to equal the chain ID.

This method takes no parameters and is available on every tier.

Parameters

This method takes no parameters.

Returns

eth_chainId return value
FieldType
resultobject

Examples

curl https://<your-endpoint>/ \
  -X POST -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"eth_chainId","params":[]}'
const res = await fetch("https://<your-endpoint>/", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
  "id": 1,
  "method": "eth_chainId",
  "params": [],
  "jsonrpc": "2.0"
}),
});
const data = await res.json();
import requests
resp = requests.post("https://<your-endpoint>/", json={"id":1,"method":"eth_chainId","params":[],"jsonrpc":"2.0"})
print(resp.json())
{
  "id": 1,
  "result": "0x1",
  "jsonrpc": "2.0"
}

Usage

  1. Transport: HTTP (JSON-RPC).
  2. Networks: mainnet.
  3. Credit cost: 1 per call.

FAQ

What does eth_chainId do?
Returns the EIP-155 chain ID of the network the node is connected to, as a hex string.
How many credits does eth_chainId cost?
eth_chainId costs 1 credit(s) per call on Triport by default.
Is eth_chainId available over WebSocket?
eth_chainId is an HTTP JSON-RPC method.