Skip to main content
Glama

estimate-fee-per-gas

Calculate gas fees (in wei, gwei, or ether) for blockchain transactions to ensure timely inclusion in the next block. Adjust chain-specific fees using MetaMask MCP for secure and efficient transaction processing.

Instructions

Estimate for the fees per gas (in wei) for a transaction to be likely included in the next block.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainIdNoID of chain to use when fetching data.
formatUnitsNoUnits to use when formatting result.gwei

Implementation Reference

  • The execute handler function for the 'estimate-fee-per-gas' tool. It calls wagmi's estimateFeesPerGas with the provided wagmiConfig and args, then returns a structured text response with the JSON-stringified result.
    execute: async (args) => { const result = await estimateFeesPerGas(wagmiConfig, args); return { content: [ { type: "text", text: JSONStringify(result), }, ], }; },
  • Zod schema defining the input parameters for the tool: optional chainId (number) and optional formatUnits (enum: ether/gwei/wei, default gwei).
    parameters: z.object({ chainId: z.coerce.number().optional().describe("ID of chain to use when fetching data."), formatUnits: z.enum(["ether", "gwei", "wei"]).default("gwei").optional().describe("Units to use when formatting result."), }),
  • The server.addTool call within the registerEstimateFeePerGasTools function, which registers the 'estimate-fee-per-gas' tool including its name, description, input schema, and handler.
    server.addTool({ name: "estimate-fee-per-gas", description: "Estimate for the fees per gas (in wei) for a transaction to be likely included in the next block.", parameters: z.object({ chainId: z.coerce.number().optional().describe("ID of chain to use when fetching data."), formatUnits: z.enum(["ether", "gwei", "wei"]).default("gwei").optional().describe("Units to use when formatting result."), }), execute: async (args) => { const result = await estimateFeesPerGas(wagmiConfig, args); return { content: [ { type: "text", text: JSONStringify(result), }, ], }; }, });
  • Invocation of the registerEstimateFeePerGasTools function within the main registerTools function, effectively registering the tool on the MCP server.
    registerEstimateFeePerGasTools(server, wagmiConfig);

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/Xiawpohr/metamask-mcp'

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