TriportRPC

eth_chainId

POSThttps://api.triport.io/v1/ethereum

Returns the EIP-155 chain ID of the network the node is connected to, as a hex string.

Ethereumeth_read_rpcfree — 10 RPS · basic — 20 RPS · pro — 100 RPS · business — 250 RPS

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
Pass an empty array [] as params.

Response

Response fields

FieldTypeDescription
resultstringEIP-155 chain ID as a hex-encoded quantity. 0x1 is Ethereum mainnet.

Errors

CodeMeaningWhen it happens
-32001trial_expiredThe API key's trial period has ended; upgrade to a paid tier to continue.
-32003rate_limitedYou 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));   // 1

TypeScript 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));   // 1

Python (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))     # 1

Notes

  • The result is a hex quantity — decode it with parseInt(result, 16) (JS) or int(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_version for the legacy decimal network ID, and eth_blockNumber to read the current head once you have confirmed the network.