estimate_gas_price
Estimate current Ethereum transaction gas prices to optimize blockchain operations and manage network costs effectively.
Instructions
Estimate current gas price
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxFeePerGas | No | Whether to include maxFeePerGas and maxPriorityFeePerGas |
Implementation Reference
- index.ts:1077-1087 (handler)The handler function that implements the core logic of the 'estimate_gas_price' tool. It validates the input parameters, fetches the current gas price using Alchemy SDK's core.getGasPrice(), and optionally formats it to gwei units based on the maxFeePerGas flag before returning.private async handleEstimateGasPrice(args: Record<string, unknown>) { const params = this.validateAndCastParams<EstimateGasPriceParams>( args, isValidEstimateGasPriceParams, "Invalid gas price parameters" ); const gasPrice = await this.alchemy.core.getGasPrice(); return params.maxFeePerGas ? { gasPrice: Utils.formatUnits(gasPrice, "gwei") } : { gasPrice }; }
- index.ts:921-933 (registration)The tool registration in the listTools response, defining the name, description, and input schema for 'estimate_gas_price'.name: "estimate_gas_price", description: "Estimate current gas price", inputSchema: { type: "object", properties: { maxFeePerGas: { type: "boolean", description: "Whether to include maxFeePerGas and maxPriorityFeePerGas", }, }, }, },
- index.ts:92-92 (schema)TypeScript type definition for the input parameters of the estimate_gas_price tool.type EstimateGasPriceParams = { maxFeePerGas?: boolean };
- index.ts:340-348 (helper)Validation function used to check and cast input arguments for the estimate_gas_price handler.const isValidEstimateGasPriceParams = ( args: any ): args is EstimateGasPriceParams => { return ( typeof args === "object" && args !== null && (args.maxFeePerGas === undefined || typeof args.maxFeePerGas === "boolean") ); };
- index.ts:994-998 (registration)Dispatch case in the CallToolRequestSchema handler that routes to the specific estimate_gas_price handler.case "estimate_gas_price": result = await this.handleEstimateGasPrice( request.params.arguments ); break;