getChains
Action for getting all configured Starknet chains.
Import
import { getChains } from "starkweb/core";
Usage
index.ts
import { getChains } from "starkweb/core";
import { config } from "./config";
const chains = getChains(config);
// Access chain information
chains.forEach((chain) => {
console.log("Chain ID:", chain.chain_id);
console.log("Chain Name:", chain.name);
});
Return Type
import { type GetChainsReturnType } from "starkweb/core";
readonly Chain[]
Array of configured chain objects, where each chain contains network information like chain ID, name, and other properties.
Example
example.ts
import { getChains } from "starkweb/core";
import { config } from "./config";
const chains = getChains(config);
// Find specific chain
const mainnet = chains.find((chain) => chain.chain_id === "0x534e5f4d41494e");
if (mainnet) {
console.log("Mainnet configuration:", {
name: mainnet.name,
chainId: mainnet.chain_id,
rpcUrls: mainnet.rpcUrls,
});
}
// List all configured chains
chains.forEach((chain, index) => {
console.log(`Chain ${index + 1}:`, {
name: chain.name,
chainId: chain.chain_id,
});
});