get_chain_id
Retrieve the chain ID for a specified blockchain network by providing the chain name, enabling accurate identification in blockchain interactions via the Etherscan MCP Tool.
Instructions
Get the chain ID for a given chain name
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chain_name | Yes | The name of the chain to get the chain ID for |
Implementation Reference
- index.ts:283-305 (handler)The handler function that implements the core logic of the 'get_chain_id' tool. It retrieves the chain name from the request arguments and looks up the corresponding chain ID from the chainIdMapping object, returning a formatted text response 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` } ] }; } }
- index.ts:97-110 (schema)The ToolDefinition object that defines the name, description, and input schema (requiring 'chain_name' string) 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"] } };
- index.ts:216-223 (registration)The toolDefinitions object where the 'get_chain_id' tool (via getChainId) is registered and included in the server's capabilities for listing and execution.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)The switch case in the callToolHandler that registers and routes calls to the 'get_chain_id' handler function.case getChainId.name: return await handleGetChainId(req);
- index.ts:34-95 (helper)The chainIdMapping object that provides the data lookup for chain names to chain IDs, directly used by the get_chain_id handler.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, };