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";
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states a read operation ('Get'), implying it's likely non-destructive, but doesn't disclose any behavioral traits such as error conditions, performance characteristics, or what happens if the wallet isn't properly connected, which is insufficient for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence that directly states the tool's purpose without any redundant or unnecessary words. It's appropriately sized and front-loaded, making it highly efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (one optional parameter) and high schema coverage, the description is minimally adequate. However, with no annotations and no output schema, it lacks details on return values or potential errors, leaving gaps in completeness for a tool that interacts with wallet connectivity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the parameter 'wallet' fully documented in the schema. The description adds no additional parameter information beyond what the schema provides, so it meets the baseline score of 3 where the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get') and the resource ('chain ID the wallet is connected to'), making the purpose understandable. However, it doesn't explicitly differentiate from sibling tools like 'network_get_network' or 'wallet_get_address', which might also involve network/wallet state queries, so it doesn't reach the highest score for sibling distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. For example, it doesn't clarify if this is for checking the current network context or how it differs from other network-related tools in the sibling list, leaving the agent without usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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