Skip to main content

getChainId

Gets the chain ID if its set, otherwise gets the chain ID from the access node

Import​

You can import the entire package and access the function:


_10
import * as fcl from "@onflow/fcl"
_10
_10
fcl.getChainId(opts)

Or import directly the specific function:


_10
import { getChainId } from "@onflow/fcl"
_10
_10
getChainId(opts)

Usage​


_10
// Get chain ID using configured access node
_10
import * as fcl from "@onflow/fcl"
_10
_10
const chainId = await fcl.getChainId()
_10
console.log("Connected to:", chainId) // "testnet" or "mainnet"

Parameters​

opts (optional)​

  • Type:

_10
export interface GetChainIdOptions {
_10
node?: unknown
_10
enableRequestLogging?: boolean
_10
[key: string]: any
_10
}

  • Description: Optional configuration parameters

Properties:​

  • node - Override the access node URL for this request instead of using the configured one
  • enableRequestLogging - Enable logging for the chain ID request

Returns​

Promise<string>

Promise that resolves to the chain ID string (e.g., "mainnet", "testnet", "local")


Rate this page