Skip to main content
Glama
getOneBlock.ts2.17 kB
import axios, { AxiosResponse } from "axios"; import { z } from "zod"; import { baseUri, chainName } from "../../constants"; interface BlockResponse { base_fee_per_gas: string; burn_fee: string; chain_name: string; difficulty: string; extra_data: string; gas_limit: string; gas_used: string; hash: string; logs_bloom: string; miner: string; nonce: string; number: number; parent_hash: string; receipt_root: string; sha3_uncles: string; size: number; state_root: string; timestamp: string; total_difficulty: string; transaction_count: number; transactions_root: string; withdrawals_root: string; } export default function(server: any) { server.tool( "getOneBlock", "Get a single block", { chainName: z.literal(chainName), blockHeight: z .string() .describe("Block number to fetch or 'latest' for the latest block"), authToken: z .string() .describe("Authorization token for accessing the Somnia API"), }, { title: "Get a Single Block", readOnlyHint: true, description: "Fetch a single block by its height.", destructiveHint: false, }, async (args:any) => { const { chainName, blockHeight, authToken } = args; try { const response: AxiosResponse<BlockResponse> = await axios.get( `${baseUri}/${chainName}/v1/block/${blockHeight}`, { headers: { "Authorization": `Bearer ${authToken}`, "Content-Type": "application/json", "Accept": "application/json", }, } ); return { content: [ { type: "text", text: `Block Data: ${JSON.stringify(response.data)}`, }, ], _meta: { blockData: response.data, }, }; } catch (error) { return { content: [ { type: "text", text: `Error fetching block: ${error}`, }, ], _meta: { blockData: null, }, }; } } ); }

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/vastavikadi/somnia-mcp'

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