@somnia-chain/markets-sdk


@somnia-chain/markets-sdk / chains / getSomniaChain

Function: getSomniaChain()

getSomniaChain(chainId): Chain | null

Defined in: packages/sdk/src/chains/index.ts:117

Resolve a chain id to its definition, or null when it isn't a Somnia network we ship. The chainId a deployment manifest carries is a plain number, so this is the bridge from "the env told me 50312" to a viem Chain.

Details

  • chainId: Chain id to look up (e.g. 50312).
  • Returns: The matching viem Chain, or null if it isn't one of ours.

Example (Resolving a deployment chain)

ts
import { getSomniaChain, defineChain } from "@somnia-chain/markets-sdk/chains";

const chain =
  getSomniaChain(deployment.chainId) ??
  defineChain({
    id: deployment.chainId,
    name: "Somnia",
    nativeCurrency: { name: "STT", symbol: "STT", decimals: 18 },
    rpcUrls: { default: { http: [rpcUrl] } },
  });

Parameters

chainId

number

Returns

Chain | null