Skip to main content
Glama

eth_gasPrice

Get the current Ethereum gas price in wei to estimate transaction costs before sending blockchain operations.

Instructions

Retrieves the current gas price in wei

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'eth_gasPrice' tool. It calls makeRpcCall('eth_gasPrice'), parses the hex result to wei and gwei, and returns formatted text output or error.
    async () => { try { console.error('Getting current gas price'); const gasPrice = await makeRpcCall('eth_gasPrice'); // Convert hex gas price to decimal and then to Gwei for readability const gasPriceWei = parseInt(gasPrice, 16); const gasPriceGwei = gasPriceWei / 1e9; return { content: [{ type: "text", text: `Current Gas Price:\n${gasPriceWei} Wei\n${gasPriceGwei.toFixed(2)} Gwei` }] }; } catch (error) { return { content: [{ type: "text", text: `Error: Failed to get gas price. ${error.message}` }], isError: true }; } }
  • index.js:135-162 (registration)
    Registers the 'eth_gasPrice' tool using server.tool method, specifying the tool name, description, empty input schema (no parameters), and inline handler function.
    // Tool 2: eth_gasPrice - Gets the current gas price server.tool( 'eth_gasPrice', 'Retrieves the current gas price in wei', {}, async () => { try { console.error('Getting current gas price'); const gasPrice = await makeRpcCall('eth_gasPrice'); // Convert hex gas price to decimal and then to Gwei for readability const gasPriceWei = parseInt(gasPrice, 16); const gasPriceGwei = gasPriceWei / 1e9; return { content: [{ type: "text", text: `Current Gas Price:\n${gasPriceWei} Wei\n${gasPriceGwei.toFixed(2)} Gwei` }] }; } catch (error) { return { content: [{ type: "text", text: `Error: Failed to get gas price. ${error.message}` }], isError: true }; } } );
  • Helper utility function 'makeRpcCall' used by the eth_gasPrice handler to send JSON-RPC requests to the Ethereum RPC endpoint.
    async function makeRpcCall(method, params = []) { try { const response = await axios.post(ETH_RPC_URL, { jsonrpc: '2.0', id: 1, method, params }); if (response.data.error) { throw new Error(`RPC Error: ${response.data.error.message}`); } return response.data.result; } catch (error) { console.error(`Error making RPC call to ${method}:`, error.message); throw error; } }
Install Server

Other Tools

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/0xKoda/eth-mcp'

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