Skip to main content
Glama

watch-contract-events

Monitor specific smart contract events on the Monad testnet by specifying the contract address, event name, and ABI. Track events starting from a chosen block number for accurate data analysis.

Instructions

Watch for smart contract events on Monad testnet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
abiYesContract ABI
addressYesContract address to watch
eventNameYesName of the event to watch
fromBlockNoStart watching from this block number

Implementation Reference

  • The main handler function that implements the tool logic. It parses the ABI to find the event, queries past logs using viem's publicClient.getLogs, and returns the events as text content or an error message.
    async ({ address, eventName, abi, fromBlock }) => { try { const parsedAbi = JSON.parse(abi); const eventAbi = parsedAbi.find( (item: any) => item.type === 'event' && item.name === eventName ); if (!eventAbi) { throw new Error(`Event ${eventName} not found in ABI`); } // Get past events const logs = await publicClient.getLogs({ address: address as `0x${string}`, event: parseAbiItem(JSON.stringify(eventAbi)) as any, fromBlock: fromBlock ? BigInt(fromBlock) : undefined, }); return { content: [ { type: "text", text: `Found ${logs.length} events for ${eventName} at ${address}:\n${JSON.stringify(logs, null, 2)}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Failed to watch events. Error: ${error instanceof Error ? error.message : String(error)}`, }, ], }; }
  • Zod-based input schema defining the parameters for the watch-contract-events tool.
    { address: z.string().describe("Contract address to watch"), eventName: z.string().describe("Name of the event to watch"), abi: z.string().describe("Contract ABI"), fromBlock: z.string().optional().describe("Start watching from this block number"), },
  • Direct registration of the tool using server.tool() within the contractEventProvider function, specifying name, description, input schema, and handler.
    export function contractEventProvider(server: McpServer) { server.tool( "watch-contract-events", "Watch for smart contract events on Monad testnet", { address: z.string().describe("Contract address to watch"), eventName: z.string().describe("Name of the event to watch"), abi: z.string().describe("Contract ABI"), fromBlock: z.string().optional().describe("Start watching from this block number"), }, async ({ address, eventName, abi, fromBlock }) => { try { const parsedAbi = JSON.parse(abi); const eventAbi = parsedAbi.find( (item: any) => item.type === 'event' && item.name === eventName ); if (!eventAbi) { throw new Error(`Event ${eventName} not found in ABI`); } // Get past events const logs = await publicClient.getLogs({ address: address as `0x${string}`, event: parseAbiItem(JSON.stringify(eventAbi)) as any, fromBlock: fromBlock ? BigInt(fromBlock) : undefined, }); return { content: [ { type: "text", text: `Found ${logs.length} events for ${eventName} at ${address}:\n${JSON.stringify(logs, null, 2)}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Failed to watch events. Error: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );
  • The contractProvider function calls contractEventProvider(server), which registers the watch-contract-events tool among contract tools.
    export function contractProvider(server: McpServer) { deployContractProvider(server); contractEventProvider(server); }
  • src/index.ts:23-27 (registration)
    In the main server initialization, contractProvider(server) is called, triggering the registration chain for the watch-contract-events tool.
    // Register available tools walletProvider(server); contractProvider(server); nftProvider(server); blockProvider(server);

Other Tools

Related 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/lispking/monad-mcp-server'

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