get-gas-prices
Retrieve current gas prices in Gwei for transactions on the chain with ID 175.
Instructions
Get current gas prices in Gwei
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:248-261 (handler)The handler for the "get-gas-prices" tool, which calls etherscanService.getGasOracle() and formats the response with current gas prices.if (name === "get-gas-prices") { try { const prices = await etherscanService.getGasOracle(); const response = `Current Gas Prices:\n` + `Safe Low: ${prices.safeGwei} Gwei\n` + `Standard: ${prices.proposeGwei} Gwei\n` + `Fast: ${prices.fastGwei} Gwei`; return { content: [{ type: "text", text: response }], }; } catch (error) { throw error; } }
- Type definition (interface) for the gas prices returned by getGasOracle().export interface GasPrice { safeGwei: string; proposeGwei: string; fastGwei: string; }
- src/server.ts:127-134 (registration)Registration of the "get-gas-prices" tool in the ListTools response, defining name, description, and input schema (no parameters).{ name: "get-gas-prices", description: "Get current gas prices in Gwei", inputSchema: { type: "object", properties: {}, }, },
- The core implementation in EtherscanService.getGasOracle(), fetching gas oracle data from Etherscan API and parsing SafeGasPrice, ProposeGasPrice, FastGasPrice.async getGasOracle(): Promise<GasPrice> { try { // Get current gas prices const result = await fetch( `https://api.etherscan.io/api?module=gastracker&action=gasoracle&apikey=${this.provider.apiKey}` ); const data = await result.json(); if (data.status !== "1" || !data.result) { throw new Error(data.message || "Failed to fetch gas prices"); } return { safeGwei: data.result.SafeGasPrice, proposeGwei: data.result.ProposeGasPrice, fastGwei: data.result.FastGasPrice }; } catch (error) { if (error instanceof Error) { throw new Error(`Failed to get gas prices: ${error.message}`); } throw error; } }