Skip to main content
Glama

get_chain_id

Retrieve the unique chain ID for a specified blockchain network to enable proper network configuration and transaction routing.

Instructions

Get the chain ID for a given chain name

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chain_nameYesThe name of the chain to get the chain ID for

Implementation Reference

  • The main handler function for the get_chain_id tool. It extracts the chain_name from the request, looks it up in the chainIdMapping, and returns a text response with the chain ID or an error if not found.
    async function handleGetChainId(req: any) {
        const chainName = req.params.arguments.chain_name;
    
        if (chainIdMapping[chainName] != null) {
            return {
                content: [
                    {
                        type: "text",
                        text: `Chain ID for ${chainName}: ${chainIdMapping[chainName]}`,
                    },
                ]
            };
        } else {
            return {
                content: [
                    {
                        type: "text",
                        text: `Chain ${chainName} not found`
                    }
                ]
            };
        }
    }
  • ToolDefinition object defining the name, description, and input schema for the get_chain_id tool.
    const getChainId: ToolDefinition = {
        name: "get_chain_id",
        description: "Get the chain ID for a given chain name",
        inputSchema: {
            type: "object",
            properties: {
                chain_name: {
                    type: "string",
                    description: "The name of the chain to get the chain ID for"
                }
            },
            required: ["chain_name"]
        }
    };
  • Static mapping of chain names to their corresponding chain IDs, used by the get_chain_id handler to resolve chain_names to numeric IDs.
    const chainIdMapping: { [key: string]: number } = {
        "Ethereum Mainnet": 1,
        "Sepolia Testnet": 11155111,
        "Holesky Testnet": 17000,
        "Abstract Mainnet": 2741,
        "Abstract Sepolia Testnet": 11124,
        "ApeChain Curtis Testnet": 33111,
        "ApeChain Mainnet": 33139,
        "Arbitrum Nova Mainnet": 42170,
        "Arbitrum One Mainnet": 42161,
        "Arbitrum Sepolia Testnet": 421614,
        "Avalanche C-Chain": 43114,
        "Avalanche Fuji Testnet": 43113,
        "Base Mainnet": 8453,
        "Base Sepolia Testnet": 84532,
        "Berachain Mainnet": 80094,
        "BitTorrent Chain Mainnet": 199,
        "BitTorrent Chain Testnet": 1028,
        "Blast Mainnet": 81457,
        "Blast Sepolia Testnet": 168587773,
        "BNB Smart Chain Mainnet": 56,
        "BNB Smart Chain Testnet": 97,
        "Celo Alfajores Testnet": 44787,
        "Celo Mainnet": 42220,
        "Cronos Mainnet": 25,
        "Fraxtal Mainnet": 252,
        "Fraxtal Testnet": 2522,
        "Gnosis": 100,
        "Linea Mainnet": 59144,
        "Linea Sepolia Testnet": 59141,
        "Mantle Mainnet": 5000,
        "Mantle Sepolia Testnet": 5003,
        "Moonbase Alpha Testnet": 1287,
        "Moonbeam Mainnet": 1284,
        "Moonriver Mainnet": 1285,
        "OP Mainnet": 10,
        "OP Sepolia Testnet": 11155420,
        "Polygon Amoy Testnet": 80002,
        "Polygon Mainnet": 137,
        "Polygon zkEVM Cardona Testnet": 2442,
        "Polygon zkEVM Mainnet": 1101,
        "Scroll Mainnet": 534352,
        "Scroll Sepolia Testnet": 534351,
        "Sonic Blaze Testnet": 57054,
        "Sonic Mainnet": 146,
        "Sophon Mainnet": 50104,
        "Sophon Sepolia Testnet": 531050104,
        "Taiko Hekla L2 Testnet": 167009,
        "Taiko Mainnet": 167000,
        "Unichain Mainnet": 130,
        "Unichain Sepolia Testnet": 1301,
        "WEMIX3.0 Mainnet": 1111,
        "WEMIX3.0 Testnet": 1112,
        "World Mainnet": 480,
        "World Sepolia Testnet": 4801,
        "Xai Mainnet": 660279,
        "Xai Sepolia Testnet": 37714555429,
        "XDC Apothem Testnet": 51,
        "XDC Mainnet": 50,
        "zkSync Mainnet": 324,
        "zkSync Sepolia Testnet": 300,
    };
  • index.ts:216-223 (registration)
    toolDefinitions object where getChainId is registered by name, used for MCP capabilities and listTools.
    const toolDefinitions: { [key: string]: ToolDefinition } = {
        [getFilteredRpcList.name]: getFilteredRpcList,
        [getChainId.name]: getChainId,
        [getTotalSupply.name]: getTotalSupply,
        [getTokenBalance.name]: getTokenBalance,
        [getTokenHolders.name]: getTokenHolders,
        [getTokenHoldersCount.name]: getTokenHoldersCount
    };
  • index.ts:481-482 (registration)
    Switch case in callToolHandler that routes calls to get_chain_id to the handleGetChainId function.
    case getChainId.name:
        return await handleGetChainId(req);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/septemhill/etherscan-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server