chains
This module provides chain configuration constants, types, and utilities for the GMX protocol. It includes chain IDs, names, gas configurations, execution fee settings, and helper functions for working with different blockchain networks supported by GMX.
Types
The chains module exports the following TypeScript types for working with chain identifiers and names.
ContractsChainId
Chain IDs where GMX contracts are deployed, including testnets. Equivalent to the union of all entries in CONTRACTS_CHAIN_IDS_DEV (42161, 43114, 3637, 43113, 421614).
// Arbitrum | Avalanche | Botanix | Avalanche Fuji | Arbitrum Sepolia
type ContractsChainId = (typeof CONTRACTS_CHAIN_IDS_DEV)[number];
ContractsChainIdProduction
Production-only chain IDs where GMX contracts are deployed, excluding testnets. Equivalent to the union of CONTRACTS_CHAIN_IDS (42161, 43114, 3637).
// Arbitrum | Avalanche | Botanix
type ContractsChainIdProduction = (typeof CONTRACTS_CHAIN_IDS)[number];
SettlementChainId
Chain IDs used for settlement operations, including testnets. Equivalent to the union of SETTLEMENT_CHAIN_IDS_DEV (42161, 43114, 421614, 43113).
// Arbitrum | Avalanche | Arbitrum Sepolia | Avalanche Fuji
type SettlementChainId = (typeof SETTLEMENT_CHAIN_IDS_DEV)[number];
SourceChainId
Chain IDs from which assets can be bridged into GMX. Includes mainnet and testnet source chains as well as GMX settlement chains.
// SOURCE_OPTIMISM_SEPOLIA | SOURCE_SEPOLIA | SOURCE_BASE_MAINNET | SOURCE_BSC_MAINNET
// | SOURCE_ETHEREUM_MAINNET | ARBITRUM_SEPOLIA | ARBITRUM | AVALANCHE | AVALANCHE_FUJI
type SourceChainId = (typeof SOURCE_CHAIN_IDS)[number];
AnyChainId
Union of all supported chain IDs across contracts, settlement, and source chains.
type AnyChainId = ContractsChainId | SettlementChainId | SourceChainId;
ChainName
Human-readable name for a supported chain. Returned by getChainName(). The value "Unknown" is returned for unrecognized chain IDs.
type ChainName =
| "Arbitrum"
| "Avalanche"
| "Avalanche Fuji"
| "Arbitrum Sepolia"
| "Optimism Sepolia"
| "Sepolia"
| "Botanix"
| "Base"
| "BNB"
| "Ethereum"
| "Unknown";
Constants
The module exports the following constants.
Chain ID constants
Numeric chain IDs for all supported networks. Import whichever you need; you rarely need all of them.
import {
ARBITRUM,
AVALANCHE,
BOTANIX,
AVALANCHE_FUJI,
ARBITRUM_SEPOLIA,
SOURCE_ETHEREUM_MAINNET,
SOURCE_BASE_MAINNET,
SOURCE_BSC_MAINNET,
SOURCE_OPTIMISM_SEPOLIA,
SOURCE_SEPOLIA,
} from "@gmx-io/sdk/configs/chains";
console.log(ARBITRUM); // 42161
console.log(AVALANCHE); // 43114
console.log(BOTANIX); // 3637
console.log(AVALANCHE_FUJI); // 43113
console.log(ARBITRUM_SEPOLIA); // 421614
console.log(SOURCE_ETHEREUM_MAINNET); // 1
console.log(SOURCE_BASE_MAINNET); // 8453
console.log(SOURCE_BSC_MAINNET); // 56
console.log(SOURCE_OPTIMISM_SEPOLIA); // 11155420
console.log(SOURCE_SEPOLIA); // 11155111
Chain ID arrays
Readonly tuples of chain IDs grouped by role. Use these for validation or iteration instead of hardcoding values.
CONTRACTS_CHAIN_IDS— Production chains where GMX contracts are deployed:[42161, 43114, 3637]CONTRACTS_CHAIN_IDS_DEV— All contracts chains including testnets:[42161, 43114, 3637, 43113, 421614]SETTLEMENT_CHAIN_IDS— Production settlement chains:[42161, 43114]SETTLEMENT_CHAIN_IDS_DEV— Settlement chains including testnets:[42161, 43114, 421614, 43113]SOURCE_CHAIN_IDS— Source chains for cross-chain deposits
import { CONTRACTS_CHAIN_IDS, isContractsChain } from "@gmx-io/sdk/configs/chains";
for (const chainId of CONTRACTS_CHAIN_IDS) {
console.log(isContractsChain(chainId)); // true
}
Other constants
GMX_ACCOUNT_PSEUDO_CHAIN_ID: 0— Pseudo chain ID used internally for the GMX Account feature.botanix: Chain— ViemChaindefinition for the Botanix network. Pass tocreatePublicClientwhen connecting to Botanix.VIEM_CHAIN_BY_CHAIN_ID: Record<AnyChainId, Chain>— Map of chain ID to viemChainobject for all supported chains.
import { botanix, VIEM_CHAIN_BY_CHAIN_ID, ARBITRUM } from "@gmx-io/sdk/configs/chains";
import { createPublicClient, http } from "viem";
// Use the pre-built Botanix chain definition
const client = createPublicClient({ chain: botanix, transport: http("https://rpc.ankr.com/botanix_mainnet") });
// Or look up any chain by ID
const arbitrumChain = VIEM_CHAIN_BY_CHAIN_ID[ARBITRUM];
Methods
The module exports functions for looking up chain metadata, validating chain IDs, and reading per-chain execution fee configuration.
Chain identification
getChainName
getChainName(chainId: number): ChainName
Returns the human-readable name for a chain ID. Returns "Unknown" for unrecognized IDs.
import { getChainName, ARBITRUM, BOTANIX } from "@gmx-io/sdk/configs/chains";
console.log(getChainName(ARBITRUM)); // "Arbitrum"
console.log(getChainName(BOTANIX)); // "Botanix"
console.log(getChainName(99999)); // "Unknown"
getChainSlug
getChainSlug(chainId: number): ChainSlug
Returns the URL-friendly slug for a chain ID. Returns "unknown" for unrecognized IDs.
import { getChainSlug, ARBITRUM, AVALANCHE } from "@gmx-io/sdk/configs/chains";
console.log(getChainSlug(ARBITRUM)); // "arbitrum"
console.log(getChainSlug(AVALANCHE)); // "avalanche"
getChainIdBySlug
getChainIdBySlug(slug: string): AnyChainId | undefined
Returns the chain ID for a given slug, or undefined if not found.
import { getChainIdBySlug } from "@gmx-io/sdk/configs/chains";
console.log(getChainIdBySlug("arbitrum")); // 42161
console.log(getChainIdBySlug("unknown")); // undefined
getViemChain
getViemChain(chainId: number): Chain
Returns the viem Chain object for a chain ID. Use this when constructing a viem PublicClient or WalletClient for a dynamically selected chain.
import { getViemChain, ARBITRUM } from "@gmx-io/sdk/configs/chains";
import { createPublicClient, http } from "viem";
const chain = getViemChain(ARBITRUM);
const client = createPublicClient({ chain, transport: http("https://arb1.arbitrum.io/rpc") });
Chain classification
isContractsChain
isContractsChain(chainId: number, dev?: boolean): chainId is ContractsChainId
Returns true if the chain ID is one where GMX contracts are deployed. Pass dev: true to include testnet chains.
import { isContractsChain, ARBITRUM, AVALANCHE_FUJI } from "@gmx-io/sdk/configs/chains";
isContractsChain(ARBITRUM); // true
isContractsChain(AVALANCHE_FUJI); // false (testnet excluded by default)
isContractsChain(AVALANCHE_FUJI, true); // true (testnet included)
isTestnetChain
isTestnetChain(chainId: number): boolean
Returns true if the chain ID is a testnet. Matches Avalanche Fuji, Arbitrum Sepolia, Sepolia, and Optimism Sepolia.
import { isTestnetChain, ARBITRUM, ARBITRUM_SEPOLIA } from "@gmx-io/sdk/configs/chains";
isTestnetChain(ARBITRUM); // false
isTestnetChain(ARBITRUM_SEPOLIA); // true
isChainDisabled
isChainDisabled(chainId: ContractsChainId): boolean
Returns true if the chain is disabled in the SDK configuration.
Execution fee helpers
These functions read per-chain execution fee configuration. Use them to validate or display fee estimates before submitting orders.
getHighExecutionFee
getHighExecutionFee(chainId: number): number
Returns the "high fee" warning threshold in USD. Defaults to 5 for unknown chain IDs.
import { getHighExecutionFee, ARBITRUM } from "@gmx-io/sdk/configs/chains";
console.log(getHighExecutionFee(ARBITRUM)); // 5
getExcessiveExecutionFee
getExcessiveExecutionFee(chainId: number): number
Returns the "excessive fee" threshold in USD. Defaults to 10 for unknown chain IDs.
import { getExcessiveExecutionFee, ARBITRUM } from "@gmx-io/sdk/configs/chains";
console.log(getExcessiveExecutionFee(ARBITRUM)); // 10
getExecutionFeeConfig
getExecutionFeeConfig(chainId: ContractsChainId): { shouldUseMaxPriorityFeePerGas: boolean; defaultBufferBps: number | undefined } | undefined
Returns the execution fee configuration for a chain, including whether to use maxPriorityFeePerGas and the default buffer basis points.
getMaxFeePerGas
getMaxFeePerGas(chainId: ContractsChainId): bigint | undefined
Returns the EIP-1559 maxFeePerGas cap for a chain, or undefined if uncapped.
getGasPricePremium
getGasPricePremium(chainId: ContractsChainId): bigint | undefined
Returns the gas price premium (in wei) added to execution fee calculations.
getMaxPriorityFeePerGas
getMaxPriorityFeePerGas(chainId: ContractsChainId): bigint | undefined
Returns the maxPriorityFeePerGas value for a chain.
getMinExecutionFeeUsd
getMinExecutionFeeUsd(chainId: ContractsChainId): bigint | undefined
Returns the minimum execution fee in USD equivalent (30-decimal precision). Set on chains with volatile gas pricing, such as Botanix.
getGasPriceBuffer
getGasPriceBuffer(chainId: ContractsChainId): bigint | undefined
Returns the gas price buffer in basis points for non-EIP-1559 transaction fee calculations.
Chain metadata
getChainNativeTokenSymbol
getChainNativeTokenSymbol(chainId: ContractsChainId): string
Returns the native token symbol for a chain (for example, "ETH" for Arbitrum, "AVAX" for Avalanche, "BTC" for Botanix).
getChainWrappedTokenSymbol
getChainWrappedTokenSymbol(chainId: ContractsChainId): string
Returns the wrapped native token symbol (for example, "WETH", "WAVAX", "PBTC").
getChainDefaultCollateralSymbol
getChainDefaultCollateralSymbol(chainId: ContractsChainId): string
Returns the default collateral token symbol for a chain (for example, "USDC.e" for Arbitrum, "USDC" for Avalanche).
getExplorerUrl
getExplorerUrl(chainId: number | "layerzero" | "layerzero-testnet"): string
Returns the block explorer base URL for a chain. Also accepts "layerzero" and "layerzero-testnet" as special values for cross-chain transaction lookup.
import { getExplorerUrl, ARBITRUM } from "@gmx-io/sdk/configs/chains";
console.log(getExplorerUrl(ARBITRUM)); // "https://arbiscan.io/"
console.log(getExplorerUrl("layerzero")); // "https://layerzeroscan.com/"
getTokenExplorerUrl
getTokenExplorerUrl(chainId: number, tokenAddress: string): string
Returns the full block explorer URL for a specific token address on a chain.
import { getTokenExplorerUrl, ARBITRUM } from "@gmx-io/sdk/configs/chains";
const url = getTokenExplorerUrl(ARBITRUM, "0xaf88d065e77c8cC2239327C5EDb3A432268e5831");
// "https://arbiscan.io/token/0xaf88d065e77c8cC2239327C5EDb3A432268e5831"