Skip to main content
Glama

wallet_get_chain_id

Retrieve the chain ID of the Ethereum or EVM-compatible network connected to your wallet, ensuring accurate blockchain interactions and transaction processing.

Instructions

Get the chain ID the wallet is connected to

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
walletNoThe wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set.

Implementation Reference

  • The getChainIdHandler function implements the core logic for the wallet_get_chain_id tool. It retrieves the wallet, checks for a provider, fetches the chain ID using wallet.getChainId(), and returns a formatted success response.
    export const getChainIdHandler = async (input: any): Promise<ToolResultSchema> => { try { const wallet = await getWallet(input.wallet, input.password); if (!wallet.provider) { return createErrorResponse("Provider is required to get chain ID, please set the provider URL"); } const chainId = await wallet.getChainId(); return createSuccessResponse( `Chain ID retrieved successfully Chain ID: ${chainId.toString()} `); } catch (error) { return createErrorResponse(`Failed to get chain ID: ${(error as Error).message}`); } };
  • The input schema definition for the wallet_get_chain_id tool, specifying an optional wallet parameter.
    { name: "wallet_get_chain_id", description: "Get the chain ID the wallet is connected to", inputSchema: { type: "object", properties: { wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." } }, required: [] }
  • src/tools.ts:573-573 (registration)
    The registration mapping the 'wallet_get_chain_id' tool name to its handler function getChainIdHandler in the handlers dictionary.
    "wallet_get_chain_id": getChainIdHandler,
  • src/tools.ts:188-197 (registration)
    The tool definition in the tools array, registering the name, description, and schema for wallet_get_chain_id.
    { name: "wallet_get_chain_id", description: "Get the chain ID the wallet is connected to", inputSchema: { type: "object", properties: { wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." } }, required: [] }
  • Imports for getWallet and getProvider helpers used in the handler.
    import { ethers, providers } from "ethers"; import { ToolResultSchema } from "../types.js"; import { createSuccessResponse, createErrorResponse, getProvider, getWallet, setProvider } from "./utils.js";

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/dcSpark/mcp-cryptowallet-evm'

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