get_block_by_number
Retrieve a specific block by its block number from EVM-compatible blockchain networks using a unified interface, with optional network specification. Supports Ethereum mainnet by default.
Instructions
Get a block by its block number
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blockNumber | Yes | The block number to fetch | |
| network | No | Network name or chain ID. Defaults to Ethereum mainnet. |
Implementation Reference
- src/core/tools.ts:187-221 (registration)Registration and handler implementation of the MCP tool 'get_block_by_number'. Includes input schema with Zod validation, tool description, and the execution logic that calls the helper service.server.tool( 'get_block_by_number', 'Get a block by its block number', { blockNumber: z.number().describe('The block number to fetch'), network: z .string() .optional() .describe('Network name or chain ID. Defaults to Ethereum mainnet.') }, async ({ blockNumber, network = 'ethereum' }) => { try { const block = await services.getBlockByNumber(blockNumber, network); return { content: [ { type: 'text', text: services.helpers.formatJson(block) } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error fetching block ${blockNumber}: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } );
- src/core/tools.ts:190-196 (schema)Input schema for the get_block_by_number tool using Zod: blockNumber (number, required), network (string, optional, defaults to 'ethereum').{ blockNumber: z.number().describe('The block number to fetch'), network: z .string() .optional() .describe('Network name or chain ID. Defaults to Ethereum mainnet.') },
- src/core/services/blocks.ts:18-24 (helper)Helper service function that retrieves a specific block by number using the viem public client for the given network.export async function getBlockByNumber( blockNumber: number, network = 'ethereum' ): Promise<Block> { const client = getPublicClient(network); return await client.getBlock({ blockNumber: BigInt(blockNumber) }); }
- src/server/server.ts:18-19 (registration)High-level registration call to registerEVMTools(server), which includes the get_block_by_number tool registration.registerEVMTools(server); registerEVMPrompts(server);