Skip to main content
Glama

eth_getCode

Retrieve smart contract bytecode from any EVM-compatible blockchain address to analyze deployed contract logic and verify code execution capabilities.

Instructions

Returns code at a given address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesContract address
blockNumberNoBlock number or 'latest', 'earliest', 'pending'latest

Implementation Reference

  • The handler function for the 'eth_getCode' tool. It makes an RPC call to retrieve the contract code at the specified address and block, computes the code length, formats the response using formatResponse, and handles errors by returning an error message.
    async ({ address, blockNumber }) => {
      try {
        const result = await makeRPCCall("eth_getCode", [address, blockNumber]);
    
        return {
          content: [
            {
              type: "text",
              text: formatResponse(
                {
                  address,
                  code: result,
                  code_length: result.length,
                  block: blockNumber,
                },
                "Contract Code",
              ),
            },
          ],
        };
      } catch (error: any) {
        return {
          content: [
            {
              type: "text",
              text: `Error: ${error.message}`,
            },
          ],
        };
      }
    },
  • Zod input schema for the 'eth_getCode' tool, validating 'address' as a required string and 'blockNumber' as an optional string defaulting to 'latest'.
    {
      address: z.string().describe("Contract address"),
      blockNumber: z
        .string()
        .optional()
        .default("latest")
        .describe("Block number or 'latest', 'earliest', 'pending'"),
    },
  • src/index.ts:626-628 (registration)
    Registration of the 'eth_getCode' tool with the MCP server, specifying the tool name and description.
    server.tool(
      "eth_getCode",
      "Returns code at a given address",
  • Generic helper function used by the 'eth_getCode' handler (and others) to perform RPC calls to the Ethereum provider via ethers.js JsonRpcProvider.
      try {
        const result = await provider.send(method, params);
        return result;
      } catch (error: any) {
        throw new Error(`RPC call failed: ${error.message}`);
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states the action ('returns code') but lacks behavioral details like what 'code' entails (e.g., bytecode, runtime code), error conditions (e.g., invalid address), or performance aspects (e.g., response format, potential delays). This leaves significant gaps for a tool with no annotation support.

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, efficient sentence with zero waste. It is front-loaded and appropriately sized for its purpose, making it easy to parse without unnecessary elaboration.

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

Completeness2/5

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

Given no annotations and no output schema, the description is incomplete. It does not explain what 'code' returns (e.g., bytecode string, hex data) or handle complexities like non-contract addresses, leaving the agent without sufficient context for reliable use.

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?

Schema description coverage is 100%, so the schema fully documents parameters ('address' as contract address, 'blockNumber' with defaults). The description adds no additional meaning beyond the schema, such as explaining parameter interactions or constraints, meeting the baseline for high coverage.

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 'Returns code at a given address' clearly states the verb ('returns') and resource ('code'), making the purpose understandable. However, it does not explicitly differentiate from siblings like 'eth_getStorageAt' (which returns storage data) or 'eth_getBalance' (which returns balance), missing full 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. It lacks context such as use cases (e.g., verifying contract deployment, analyzing bytecode) or exclusions (e.g., not for non-contract addresses), leaving the agent with no usage direction.

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

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

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