get-gas-prices
Retrieve current Ethereum network gas prices in Gwei to optimize transaction costs and timing.
Instructions
Get current gas prices in Gwei
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:285-299 (handler)Executes the get-gas-prices tool by calling EtherscanService.getGasOracle(), formatting the safe, standard, and fast gas prices into a text response.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; } }
- src/server.ts:138-146 (schema)Defines the tool schema with name, description, and empty input schema (no parameters required).{ name: "get-gas-prices", description: "Get current gas prices in Gwei", inputSchema: { type: "object", properties: {}, }, }, {
- src/server.ts:63-163 (registration)Registers the get-gas-prices tool in the list of available tools returned by ListToolsRequestHandler.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "check-balance", description: "Check the ETH balance of an Ethereum address", inputSchema: { type: "object", properties: { address: { type: "string", description: "Ethereum address (0x format)", pattern: "^0x[a-fA-F0-9]{40}$", }, }, required: ["address"], }, }, { name: "get-transactions", description: "Get recent transactions for an Ethereum address", inputSchema: { type: "object", properties: { address: { type: "string", description: "Ethereum address (0x format)", pattern: "^0x[a-fA-F0-9]{40}$", }, limit: { type: "number", description: "Number of transactions to return (max 100)", minimum: 1, maximum: 100, }, }, required: ["address"], }, }, { name: "get-token-transfers", description: "Get ERC20 token transfers for an Ethereum address", inputSchema: { type: "object", properties: { address: { type: "string", description: "Ethereum address (0x format)", pattern: "^0x[a-fA-F0-9]{40}$", }, limit: { type: "number", description: "Number of transfers to return (max 100)", minimum: 1, maximum: 100, }, }, required: ["address"], }, }, { name: "get-contract-abi", description: "Get the ABI for a smart contract", inputSchema: { type: "object", properties: { address: { type: "string", description: "Contract address (0x format)", pattern: "^0x[a-fA-F0-9]{40}$", }, }, required: ["address"], }, }, { name: "get-gas-prices", description: "Get current gas prices in Gwei", inputSchema: { type: "object", properties: {}, }, }, { name: "get-ens-name", description: "Get the ENS name for an Ethereum address", inputSchema: { type: "object", properties: { address: { type: "string", description: "Ethereum address (0x format)", pattern: "^0x[a-fA-F0-9]{40}$", }, }, required: ["address"], }, }, ], }; });
- Core helper function that fetches current gas oracle data from Etherscan API and parses safeGasPrice, ProposeGasPrice, and 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; } }