get_block
Retrieve block details from the Rootstock blockchain using either block number or hash for informed blockchain analysis and operations.
Instructions
Get block information by number or hash
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blockHash | No | Block hash (alternative to blockNumber) | |
| blockNumber | No | Block number (alternative to blockHash) |
Implementation Reference
- src/index.ts:713-727 (handler)The handler function that executes the 'get_block' tool logic. It calls RootstockClient.getBlock and formats the response as MCP content.
private async handleGetBlock(params: GetBlockParams) { try { const block = await this.rootstockClient.getBlock(params.blockNumber, params.blockHash); return { content: [ { type: 'text', text: `Block Information:\n\nNumber: ${block.number}\nHash: ${block.hash}\nTimestamp: ${new Date(block.timestamp * 1000).toISOString()}\nTransactions: ${block.transactionCount}\nGas Used: ${block.gasUsed}\nGas Limit: ${block.gasLimit}\nMiner: ${block.miner}`, }, ], }; } catch (error) { throw new Error(`Failed to get block: ${error}`); } } - src/index.ts:269-285 (registration)Registration of the 'get_block' tool in the MCP server's listAvailableTools method, defining name, description, and input schema.
{ name: 'get_block', description: 'Get block information by number or hash', inputSchema: { type: 'object', properties: { blockNumber: { type: 'number', description: 'Block number (alternative to blockHash)', }, blockHash: { type: 'string', description: 'Block hash (alternative to blockNumber)', }, }, }, }, - src/types.ts:142-145 (schema)TypeScript interface defining the input parameters for the get_block tool.
export interface GetBlockParams { blockNumber?: number; blockHash?: string; } - src/rootstock-client.ts:240-270 (helper)Supporting method in RootstockClient that performs the actual blockchain RPC call to retrieve block data using ethers.js.
async getBlock(blockNumber?: number, blockHash?: string): Promise<BlockInfo> { try { let block; if (blockHash) { block = await this.getProvider().getBlock(blockHash); } else if (blockNumber !== undefined) { block = await this.getProvider().getBlock(blockNumber); } else { block = await this.getProvider().getBlock('latest'); } if (!block) { throw new Error('Block not found'); } return { number: block.number, hash: block.hash || '', parentHash: block.parentHash, timestamp: block.timestamp, gasLimit: block.gasLimit.toString(), gasUsed: block.gasUsed.toString(), miner: block.miner, difficulty: block.difficulty?.toString(), size: block.length || 0, transactionCount: block.transactions.length, }; } catch (error) { throw new Error(`Failed to get block: ${error}`); } }