Skip to main content
Glama

get_block_by_number

Retrieve block details by specifying the block number and network for BNB Chain or other supported networks. Defaults to BSC mainnet if no network is provided.

Instructions

Get a block by number

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
blockNumberYesThe block number 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_number', including description, Zod input schema (blockNumber as string, network), and handler that parses blockNumber to int, calls service.getBlockByNumber, and returns wrapped success/error response.
    server.tool( "get_block_by_number", "Get a block by number", { blockNumber: z.string().describe("The block number to look up"), network: defaultNetworkParam }, async ({ network, blockNumber }) => { try { const block = await services.getBlockByNumber( parseInt(blockNumber), network ) return mcpToolRes.success(block) } catch (error) { return mcpToolRes.error(error, "fetching block by number") } } )
  • Core handler function that retrieves the specified block using viem's 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) }) }
  • Shared Zod schema parameter for network input, used in the tool's input schema with default 'bsc'.
    export const defaultNetworkParam = z .string() .describe( "Network name (e.g. 'bsc', 'opbnb', 'ethereum', 'base', etc.) or chain ID. Supports others main popular networks. Defaults to BSC mainnet." ) .default("bsc")

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