{"record":{"id":"0f2aada6af5d258b","repo":"unionlabs/union","slug":"invalid-chain-id","errorCode":null,"errorMessage":"Invalid chain id","messagePattern":"Invalid chain id","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"typescript-sdk/src/mod.ts","lineNumber":183,"sourceCode":" * Create Union Client for EVM, Cosmos, and Aptos\n */\nexport function createUnionClient(\n  parameters: EvmClientParameters | CosmosClientParameters | AptosClientParameters,\n):\n  | ReturnType<typeof createEvmClient>\n  | ReturnType<typeof createCosmosClient>\n  | ReturnType<typeof createAptosClient>\n{\n  if (evmChainId.includes(parameters.chainId)) {\n    return createEvmClient(parameters as EvmClientParameters)\n  }\n  if (cosmosChainId.includes(parameters.chainId)) {\n    return createCosmosClient(parameters as CosmosClientParameters)\n  }\n  if (aptosChainId.includes(parameters.chainId)) {\n    return createAptosClient(parameters as AptosClientParameters)\n  }\n  throw new Error(\"Invalid chain id\")\n}\n\n/**\n * @example\n * ```ts\n * import { privateKeyToAccount } from \"viem/accounts\"\n * import { DirectSecp256k1Wallet } from \"@cosmjs/proto-signing\"\n * import { createUnionClient, hexToBytes } from \"@union/client\"\n *\n * const cosmosAccount = await DirectSecp256k1Wallet.fromKey(\n *   Uint8Array.from(hexToBytes(PRIVATE_KEY)),\n *   \"stride\"\n * )\n *\n * const clients = createMultiUnionClient([\n *   {\n *     chainId: \"11155111\",\n *     transport: http(\"https://rpc.sepolia.org\"),","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/unionlabs/union/blob/031785bb6dc6b957c624e62bc64c184409c97d7b/typescript-sdk/src/mod.ts#L165-L201","documentation":"Thrown by createUnionClient, the single entry point of the Union TypeScript SDK. It routes the parameters to createEvmClient, createCosmosClient, or createAptosClient by checking membership of parameters.chainId in the evmChainId, cosmosChainId, and aptosChainId literal arrays; if no list contains the id, the chain is unsupported and client creation fails immediately.","triggerScenarios":"Calling createUnionClient with a chainId outside the SDK's supported sets: a testnet/deprecated id (e.g. an old rollup), a chain added in a newer SDK release than the one installed, a numeric string with wrong formatting (\"0x1\" vs \"1\"), or a typo like \"strid-1\".","commonSituations":"Upgrading a chain in your app before upgrading @union/client; using a freshly launched L2/L3 not yet in evmChainId; passing chain name instead of chain id; formatting mismatches between number and string chain ids.","solutions":["Check the exported evmChainId, cosmosChainId, and aptosChainId unions from @union/client and use one of those literal values","Upgrade @union/client to the latest version, which usually adds newly supported chains","Verify formatting: EVM ids are decimal strings like \"11155111\", Cosmos ids like \"stride-internal-1\", Aptos ids per the SDK's list","If the chain is genuinely unsupported, request support or route through a supported chain's client"],"exampleFix":"// before\nconst client = createUnionClient({\n  chainId: 11155111, // number, not in the string unions\n  transport: http(rpc),\n})\n\n// after\nconst client = createUnionClient({\n  chainId: \"11155111\", // literal from evmChainId\n  transport: http(rpc),\n})","handlingStrategy":"validation","validationCode":"import { cosmosChainId, evmChainId, aptosChainId } from \"@union/client\"\n\nconst isSupportedChainId = (id: string) =>\n  evmChainId.includes(id as never) || cosmosChainId.includes(id as never) || aptosChainId.includes(id as never)\n\nif (!isSupportedChainId(chainId)) {\n  throw new Error(`Unsupported chainId ${chainId}; upgrade @union/client or use a listed id`)\n}\nconst client = createUnionClient({ ...params, chainId })","typeGuard":"import { evmChainId, cosmosChainId, aptosChainId } from \"@union/client\"\n\ntype SupportedChainId =\n  | (typeof evmChainId)[number]\n  | (typeof cosmosChainId)[number]\n  | (typeof aptosChainId)[number]\n\nconst isSupportedChainId = (id: string): id is SupportedChainId =>\n  (evmChainId as readonly string[]).includes(id) ||\n  (cosmosChainId as readonly string[]).includes(id) ||\n  (aptosChainId as readonly string[]).includes(id)","tryCatchPattern":"try {\n  const client = createUnionClient(params)\n} catch (error) {\n  if (error instanceof Error && error.message === \"Invalid chain id\") {\n    // show supported chains / offer chain selection UI\n  }\n  throw error\n}","preventionTips":["Type chainId as the SDK's exported union so unsupported ids fail at compile time","Upgrade @union/client when adding new chains to your app","Normalize chain id formatting (decimal strings for EVM) before client creation"],"tags":["typescript-sdk","chain-id","configuration","routing"],"backgroundTag":null,"analyzedSha":"031785bb6dc6b957c624e62bc64c184409c97d7b","analyzedAt":"2026-08-16T06:24:09.996Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}