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}`); } }

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