Skip to main content
Glama

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
NameRequiredDescriptionDefault
maxFeePerGasNoWhether to include maxFeePerGas and maxPriorityFeePerGas

Implementation Reference

  • 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", }, }, }, },
  • TypeScript type definition for the input parameters of the estimate_gas_price tool.
    type EstimateGasPriceParams = { maxFeePerGas?: boolean };
  • 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;

Latest Blog Posts

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/itsanishjain/alchemy-sdk-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server