eth_call
Execute smart contract calls without creating blockchain transactions to read data, test functions, or simulate contract interactions on EVM networks.
Instructions
Executes a new message call immediately without creating a transaction
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blockNumber | No | Block number or 'latest', 'earliest', 'pending' | latest |
| data | Yes | Data to send (hex string) | |
| from | No | From address (optional) | |
| gas | No | Gas limit (optional) | |
| gasPrice | No | Gas price (optional) | |
| to | Yes | Contract address | |
| value | No | Value in wei (optional) |
Implementation Reference
- src/index.ts:448-488 (handler)The handler function for the 'eth_call' tool. It constructs a transaction object from the input parameters and uses the makeRPCCall helper to execute the eth_call RPC method via the ethers provider, then formats and returns the result.async ({ to, data, blockNumber, from, value, gas, gasPrice }) => { try { const txObject: any = { to, data, }; if (from) txObject.from = from; if (value) txObject.value = value; if (gas) txObject.gas = gas; if (gasPrice) txObject.gasPrice = gasPrice; const result = await makeRPCCall("eth_call", [txObject, blockNumber]); return { content: [ { type: "text", text: formatResponse( { result, to, data, block: blockNumber, }, "Contract Call Result", ), }, ], }; } catch (error: any) { return { content: [ { type: "text", text: `Error: ${error.message}`, }, ], }; } },
- src/index.ts:435-447 (schema)Zod input schema defining the parameters for the eth_call tool: to (required), data (required), and optional blockNumber, from, value, gas, gasPrice.{ to: z.string().describe("Contract address"), data: z.string().describe("Data to send (hex string)"), blockNumber: z .string() .optional() .default("latest") .describe("Block number or 'latest', 'earliest', 'pending'"), from: z.string().optional().describe("From address (optional)"), value: z.string().optional().describe("Value in wei (optional)"), gas: z.string().optional().describe("Gas limit (optional)"), gasPrice: z.string().optional().describe("Gas price (optional)"), },
- src/index.ts:432-434 (registration)Registration of the 'eth_call' MCP tool using server.tool(name, description, inputSchema, handler).server.tool( "eth_call", "Executes a new message call immediately without creating a transaction",
- src/index.ts:89-96 (helper)Generic helper function that performs RPC calls to the Ethereum provider using ethers.JsonRpcProvider.send(). Directly used by the eth_call handler at line 460.async function makeRPCCall(method: string, params: any[] = []): Promise<any> { try { const result = await provider.send(method, params); return result; } catch (error: any) { throw new Error(`RPC call failed: ${error.message}`); } }