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
| Name | Required | Description | Default |
|---|---|---|---|
| abi | Yes | Contract ABI | |
| address | Yes | Contract address to watch | |
| eventName | Yes | Name of the event to watch | |
| fromBlock | No | Start watching from this block number |
Implementation Reference
- src/tools/contract/events.ts:23-58 (handler)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)}`, }, ], }; }
- src/tools/contract/events.ts:17-22 (schema)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"), },
- src/tools/contract/events.ts:13-60 (registration)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)}`, }, ], }; } } );
- src/tools/contract/index.ts:5-8 (registration)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);