eth_getTransactionCount
Check how many transactions an Ethereum address has sent to determine account activity and calculate nonce values for new transactions.
Instructions
Returns the number of transactions sent from an address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Address to check transaction count for | |
| blockNumber | No | Block number or 'latest', 'earliest', 'pending' | latest |
Implementation Reference
- src/index.ts:241-286 (registration)Registration of the 'eth_getTransactionCount' tool using server.tool, which includes the name, description, input schema, and handler function.server.tool( "eth_getTransactionCount", "Returns the number of transactions sent from an address", { address: z.string().describe("Address to check transaction count for"), blockNumber: z .string() .optional() .default("latest") .describe("Block number or 'latest', 'earliest', 'pending'"), }, async ({ address, blockNumber }) => { try { const result = await makeRPCCall("eth_getTransactionCount", [ address, blockNumber, ]); const nonce = parseInt(result, 16); return { content: [ { type: "text", text: formatResponse( { address, nonce_hex: result, nonce_decimal: nonce, block: blockNumber, }, "Transaction Count (Nonce)", ), }, ], }; } catch (error: any) { return { content: [ { type: "text", text: `Error: ${error.message}`, }, ], }; } }, );
- src/index.ts:252-285 (handler)Handler function that executes the eth_getTransactionCount RPC call via makeRPCCall, parses the nonce, formats the response using formatResponse, and handles errors.async ({ address, blockNumber }) => { try { const result = await makeRPCCall("eth_getTransactionCount", [ address, blockNumber, ]); const nonce = parseInt(result, 16); return { content: [ { type: "text", text: formatResponse( { address, nonce_hex: result, nonce_decimal: nonce, block: blockNumber, }, "Transaction Count (Nonce)", ), }, ], }; } catch (error: any) { return { content: [ { type: "text", text: `Error: ${error.message}`, }, ], }; } },
- src/index.ts:244-251 (schema)Zod schema defining input parameters: required 'address' string and optional 'blockNumber' string defaulting to 'latest'.{ address: z.string().describe("Address to check transaction count for"), blockNumber: z .string() .optional() .default("latest") .describe("Block number or 'latest', 'earliest', 'pending'"), },
- src/index.ts:89-96 (helper)Helper function that performs generic RPC calls using the ethers provider, used by the handler.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}`); } }