Skip to content
On this page

getChainId

Returns the chain ID associated with the current network

Usage

ts
import { publicClient } from './client'

const block = await publicClient.getChainId() 
// 1
ts
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'

export const publicClient = createPublicClient({
  chain: mainnet,
  transport: http()
})

Returns

number

The current chain ID.

JSON-RPC Method

Released under the MIT License.