eth_blockNumber
Get the current block number from any EVM-compatible blockchain to track network progress and synchronize with the latest state.
Instructions
Returns the number of the most recent block
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:162-190 (handler)The handler function that executes the eth_blockNumber tool. It makes an RPC call to get the latest block number in hex, parses it to decimal, adds a timestamp, and formats the response using formatResponse.async () => { try { const result = await makeRPCCall("eth_blockNumber"); const blockNumber = parseInt(result, 16); return { content: [ { type: "text", text: formatResponse( { hex: result, decimal: blockNumber, timestamp: new Date().toISOString(), }, "Latest Block Number", ), }, ], }; } catch (error: any) { return { content: [ { type: "text", text: `Error: ${error.message}`, }, ], }; }
- src/index.ts:161-161 (schema)Empty schema indicating no input parameters are required for the tool.{},
- src/index.ts:158-192 (registration)Registration of the eth_blockNumber tool using McpServer's server.tool method, specifying name, description, schema, and handler.server.tool( "eth_blockNumber", "Returns the number of the most recent block", {}, async () => { try { const result = await makeRPCCall("eth_blockNumber"); const blockNumber = parseInt(result, 16); return { content: [ { type: "text", text: formatResponse( { hex: result, decimal: blockNumber, timestamp: new Date().toISOString(), }, "Latest Block Number", ), }, ], }; } catch (error: any) { return { content: [ { type: "text", text: `Error: ${error.message}`, }, ], }; } }, );
- src/index.ts:89-96 (helper)Helper function makeRPCCall used by the handler to send the RPC request to the Ethereum provider.async function makeRPCCall(method: string, params: any[] = []): Promise<any> { try { const result = await provider.send(method, params); return result; } catch (error: any) { throw new Error(`RPC call failed: ${error.message}`); } }