Skip to main content
Glama

get_block_by_hash

Retrieve blockchain block details using a specific block hash. Supports multiple networks, including BSC, Ethereum, and others, with BSC mainnet as default.

Instructions

Get a block by hash

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
blockHashYesThe block hash to look up
networkNoNetwork name (e.g. 'bsc', 'opbnb', 'ethereum', 'base', etc.) or chain ID. Supports others main popular networks. Defaults to BSC mainnet.bsc

Implementation Reference

  • MCP tool registration for 'get_block_by_hash', including description, input schema, and handler function.
    server.tool( "get_block_by_hash", "Get a block by hash", { blockHash: z.string().describe("The block hash to look up"), network: defaultNetworkParam }, async ({ network, blockHash }) => { try { const block = await services.getBlockByHash(blockHash as Hash, network) return mcpToolRes.success(block) } catch (error) { return mcpToolRes.error(error, "fetching block by hash") } } )
  • Handler function that executes the tool: fetches block via service and returns MCP-formatted response.
    async ({ network, blockHash }) => { try { const block = await services.getBlockByHash(blockHash as Hash, network) return mcpToolRes.success(block) } catch (error) { return mcpToolRes.error(error, "fetching block by hash") } }
  • Input schema using Zod for tool parameters (blockHash and network).
    { blockHash: z.string().describe("The block hash to look up"), network: defaultNetworkParam },
  • Helper service function that retrieves a block by its hash using the viem public client.
    export async function getBlockByHash( blockHash: Hash, network = "ethereum" ): Promise<Block> { const client = getPublicClient(network) return await client.getBlock({ blockHash }) }
  • Higher-level registration call to registerBlockTools within the blocks module.
    registerBlockTools(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/bnb-chain/bnbchain-mcp'

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