eth_chainId

Returns the currently configured chain ID, a value used in replay-protected transaction signing as introduced by EIP-155.

The chain ID returned should always correspond to the information in the current known head block. This ensures that caller of this RPC method can always use the retrieved information to sign transactions built on top of the head.

If the current known head block does not specify a chain ID, the client should treat any calls to eth_chainId as though the method were not supported, and return a suitable error.

You should prefer eth_chainId over net_version, so that you can reliably identify the chain you are communicating with.

Parameters

None.

Returns

QUANTITY - integer of the current chain ID.

Request

const Web3 = require("web3");

async function main() {

	const Web3 = require('web3')
        const rpcURL = '1DLT-IP-ADDRESS' // Your RPC URL goes here
        const web3 = new Web3(rpcURL)
	
	// Query the blockchain (replace example parameters)
    	const id = await web3.eth.chainId(); 
    
	// Print the output to console
	console.log(id);
   }

main();

Result

{
  "id": 83,
  "jsonrpc": "2.0",
  "result": "0x3d" // 61
}

Last updated