eth_chainId
https://api.triport.io/v1/ethereumReturns the EIP-155 chain ID of the network the node is connected to, as a hex string.
eth_chainId returns the chain ID used for replay-protected transaction signing
as introduced in 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.
——optional[] as params.Response
Response fields
| Field | Type | Description |
|---|---|---|
result | string | EIP-155 chain ID as a hex-encoded quantity. 0x1 is Ethereum mainnet. |
Errors
| Code | Meaning | When it happens |
|---|---|---|
-32001 | trial_expired | The API key's trial period has ended; upgrade to a paid tier to continue. |
-32003 | rate_limited | You exceeded the requests-per-second limit for your tier. Back off and retry. |
Errors are returned in the standard JSON-RPC envelope. See the shared errors reference for the full error object shape and handling guidance.
Examples
JavaScript (fetch)
const res = await fetch("https://api.triport.io/v1/ethereum", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.TRIPORT_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "eth_chainId",
params: [],
}),
});
const { result } = await res.json();
console.log(result); // "0x1"
console.log(parseInt(result, 16)); // 1TypeScript SDK (@triport/sdk)
import { Triport } from "@triport/sdk";
const client = new Triport({ apiKey: process.env.TRIPORT_API_KEY! });
const chainId = await client.ethereum.rpc<string>("eth_chainId", []);
console.log(chainId); // "0x1"
console.log(parseInt(chainId, 16)); // 1Python (triport-sdk)
import os
from triport import Triport
client = Triport(api_key=os.environ["TRIPORT_API_KEY"])
chain_id = client.ethereum.rpc("eth_chainId", [])
print(chain_id) # "0x1"
print(int(chain_id, 16)) # 1Notes
- The result is a hex quantity — decode it with
parseInt(result, 16)(JS) orint(result, 16)(Python) to get the integer chain ID. - The chain ID is stable for the lifetime of a network and does not change between blocks, so the value is safe to cache for the duration of a session.
- Related: use
net_versionfor the legacy decimal network ID, andeth_blockNumberto read the current head once you have confirmed the network.