Skip to main content
Glama

call

Execute blockchain contract calls without submitting transactions to the network. Use this tool to interact with smart contracts while keeping private keys secure in MetaMask.

Instructions

Executing a new message call immediately without submitting a transaction to the network.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYesThe contract address or recipient.
dataYesA contract hashed method call with encoded args.
valueNoValue (in wei) sent with this transaction.

Implementation Reference

  • The execute handler for the 'call' MCP tool. It invokes wagmi's `call` function with the provided args, returns the result hash as JSON stringified text content, or error messages on failure.
    execute: async (args) => { try { const result = await call(wagmiConfig, args); return { content: [ { type: "text", text: JSONStringify({ hash: result, }), }, ], }; } catch (error) { if (error instanceof TransactionExecutionError) { return { content: [ { type: "text", text: error.cause.message, }, ], }; } return { content: [ { type: "text", text: (error as Error).message, }, ], }; } },
  • Zod input schema for the 'call' tool parameters: to (Address), data (Calldata), optional value (bigint).
    parameters: z.object({ to: Address.describe("The contract address or recipient."), data: Calldata.describe("A contract hashed method call with encoded args."), value: z.coerce.bigint().optional().describe("Value (in wei) sent with this transaction."), }),
  • Calldata zod schema validator used in the 'call' tool's data parameter. Validates 0x-prefixed hex string.
    export const Calldata = z.string().transform((val, ctx) => { const regex = /^0x[a-fA-F0-9]+$/; if (!regex.test(val)) { ctx.addIssue({ code: z.ZodIssueCode.custom, message: `Invalid calldata ${val}`, }); } return val as BytesType; });
  • registerCallTools function that registers the 'call' tool on the FastMCP server with name, description, schema, and handler.
    export function registerCallTools(server: FastMCP, wagmiConfig: Config): void { server.addTool({ name: "call", description: "Executing a new message call immediately without submitting a transaction to the network.", parameters: z.object({ to: Address.describe("The contract address or recipient."), data: Calldata.describe("A contract hashed method call with encoded args."), value: z.coerce.bigint().optional().describe("Value (in wei) sent with this transaction."), }), execute: async (args) => { try { const result = await call(wagmiConfig, args); return { content: [ { type: "text", text: JSONStringify({ hash: result, }), }, ], }; } catch (error) { if (error instanceof TransactionExecutionError) { return { content: [ { type: "text", text: error.cause.message, }, ], }; } return { content: [ { type: "text", text: (error as Error).message, }, ], }; } }, }); };
  • Invocation of registerCallTools within the main registerTools function to register all tools including 'call'.
    registerCallTools(server, wagmiConfig);

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/Xiawpohr/metamask-mcp'

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