get_gas_estimate
Estimate Base network gas costs for multi-wallet trading operations to calculate transaction fees before executing buys, sells, or transfers.
Instructions
Get current Base gas price and estimate cost for N wallet operations.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| num_wallets | Yes | Number of wallets involved | |
| operation_type | Yes | Type of operation to estimate |
Implementation Reference
- src/index.ts:714-745 (handler)Handler function implementing gas estimation logic.
async function handleGasEstimate( args: z.infer<typeof GasEstimateSchema> ): Promise<string> { const provider = getProvider(); const feeData = await provider.getFeeData(); const gasPrice = feeData.gasPrice ?? 0n; const maxFeePerGas = feeData.maxFeePerGas ?? gasPrice; const maxPriorityFee = feeData.maxPriorityFeePerGas ?? 0n; const gasLimit = GAS_LIMITS[args.operation_type] ?? 200_000n; const costPerTx = gasLimit * maxFeePerGas; const totalCost = costPerTx * BigInt(args.num_wallets); // Add 20% buffer const bufferedTotal = totalCost + totalCost / 5n; return JSON.stringify( { gas_price_gwei: ethers.formatUnits(gasPrice, "gwei"), max_fee_per_gas_gwei: ethers.formatUnits(maxFeePerGas, "gwei"), max_priority_fee_gwei: ethers.formatUnits(maxPriorityFee, "gwei"), operation: args.operation_type, gas_limit_per_tx: gasLimit.toString(), num_wallets: args.num_wallets, cost_per_tx_eth: formatEth(costPerTx), total_cost_eth: formatEth(totalCost), total_with_buffer_eth: formatEth(bufferedTotal), buffer: "20%", }, null, 2 - src/index.ts:161-166 (schema)Zod schema for input validation of get_gas_estimate.
const GasEstimateSchema = z.object({ num_wallets: z.number().describe("Number of wallets involved"), operation_type: z .enum(["buy", "sell", "transfer"]) .describe("Type of operation to estimate"), }); - src/index.ts:889-908 (registration)Tool registration in the MCP server definition.
{ name: "get_gas_estimate", description: "Get current Base gas price and estimate cost for N wallet operations.", inputSchema: { type: "object" as const, properties: { num_wallets: { type: "number", description: "Number of wallets involved", }, operation_type: { type: "string", enum: ["buy", "sell", "transfer"], description: "Type of operation to estimate", }, }, required: ["num_wallets", "operation_type"], }, },