Skip to main content
Glama

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
NameRequiredDescriptionDefault
blockNumberYesThe block number to fetch
networkNoNetwork name or chain ID. Defaults to Ethereum mainnet.

Implementation Reference

  • 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 }; } } );
  • 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.') },
  • 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) }); }
  • High-level registration call to registerEVMTools(server), which includes the get_block_by_number tool registration.
    registerEVMTools(server); registerEVMPrompts(server);

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/chulanpro5/evm-mcp-server'

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