GAS_PRICE
Check current gas prices on blockchain networks to optimize transaction costs when using decentralized exchanges.
Instructions
Get gas price
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chain | No | The blockchain network to execute the transaction on. uses fraxtal as default | fraxtal |
Implementation Reference
- src/tools/chain.ts:13-35 (handler)The main handler function that executes the GAS_PRICE tool. It resolves the chain, uses ChainService to fetch the gas price, and returns it as JSON.export const gasPrice = async (args: z.infer<typeof chainParamsSchema>) => { try { const inputChain = args.chain.toLowerCase(); const chainObject = getChainFromName(inputChain); console.error(`[GAS_PRICE] Using chain: ${chainObject} (${chainObject.id})`); const service = new ChainService(); const gasPrice = await service.gasPrice(chainObject.id); if (gasPrice instanceof Error) { return `Error fetching gasPrice: ${gasPrice.message}`; } return JSON.stringify(gasPrice, null, 2); } catch (error: unknown) { const message = error instanceof Error ? error.message : "An unknown error occurred while fetching gasPrice."; console.error(`[GAS_PRICE] Error: ${message}`); throw new Error(`Failed to fetch gasPrice: ${message}`); } };
- src/tools/index.ts:22-27 (registration)Registration of the GAS_PRICE tool in the tools export, specifying name, description, parameters schema, and execute handler.gasPrice: { name: "GAS_PRICE", description: "Get gas price", parameters: chainParamsSchema, execute: chainExecute.gasPrice },
- src/types.ts:4-12 (schema)Zod schema for chainParams used as input parameters for GAS_PRICE tool.export const chainParamsSchema = z.object({ chain: z .string() .optional() .describe( "The blockchain network to execute the transaction on. uses fraxtal as default", ) .default("fraxtal") });