import { type Block, type Hash } from "viem"
import { getPublicClient } from "./clients.js"
/**
* Get the current block number for a specific network
*/
export async function getBlockNumber(network = "ethereum"): Promise<bigint> {
const client = getPublicClient(network)
return await client.getBlockNumber()
}
/**
* Get a block by number for a specific network
*/
export async function getBlockByNumber(
blockNumber: number,
network = "ethereum"
): Promise<Block> {
const client = getPublicClient(network)
return await client.getBlock({ blockNumber: BigInt(blockNumber) })
}
/**
* Get a block by hash for a specific network
*/
export async function getBlockByHash(
blockHash: Hash,
network = "ethereum"
): Promise<Block> {
const client = getPublicClient(network)
return await client.getBlock({ blockHash })
}
/**
* Get the latest block for a specific network
*/
export async function getLatestBlock(network = "ethereum"): Promise<Block> {
const client = getPublicClient(network)
return await client.getBlock()
}
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