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
| Name | Required | Description | Default |
|---|---|---|---|
| to | Yes | The contract address or recipient. | |
| data | Yes | A contract hashed method call with encoded args. | |
| value | No | Value (in wei) sent with this transaction. |
Implementation Reference
- src/tools/call.ts:19-53 (handler)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, }, ], }; } },
- src/tools/call.ts:14-18 (schema)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."), }),
- src/utils/evm-schema.ts:19-30 (schema)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; });
- src/tools/call.ts:10-55 (registration)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, }, ], }; } }, }); };
- src/tools/register-tools.ts:33-33 (registration)Invocation of registerCallTools within the main registerTools function to register all tools including 'call'.registerCallTools(server, wagmiConfig);