Skip to main content
Glama

estimate_gas

Calculate gas fees for transactions on supported blockchain networks like BSC, Ethereum, and more using recipient address, value, and data inputs. Defaults to BSC mainnet.

Instructions

Estimate the gas cost for a transaction

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataNoThe transaction data as a hex string
networkNoNetwork name (e.g. 'bsc', 'opbnb', 'ethereum', 'base', etc.) or chain ID. Supports others main popular networks. Defaults to BSC mainnet.bsc
toYesThe recipient address
valueNoThe amount of ETH to send in ether (e.g., '0.1')

Implementation Reference

  • The main handler function for the 'estimate_gas' MCP tool. It processes input parameters, constructs the transaction params, calls the services.estimateGas helper, and returns the estimated gas in a standardized MCP response format.
    async ({ to, value, data, network }) => {
      try {
        const params: any = { to: to as Address }
    
        if (value) {
          params.value = services.helpers.parseEther(value)
        }
    
        if (data) {
          params.data = data as `0x${string}`
        }
    
        const gas = await services.estimateGas(params, network)
    
        return mcpToolRes.success({
          network,
          estimatedGas: gas.toString()
        })
      } catch (error) {
        return mcpToolRes.error(error, "estimating gas")
      }
    }
  • Zod schema defining the input parameters for the 'estimate_gas' tool: 'to' (required address), 'value' (optional ETH amount), 'data' (optional hex data), 'network' (chain identifier).
    {
      to: z.string().describe("The recipient address"),
      value: z
        .string()
        .optional()
        .describe("The amount of ETH to send in ether (e.g., '0.1')"),
      data: z
        .string()
        .optional()
        .describe("The transaction data as a hex string"),
      network: defaultNetworkParam
    },
  • The registration of the 'estimate_gas' tool on the MCP server within registerTransactionTools, including name, description, input schema, and handler function.
    server.tool(
      "estimate_gas",
      "Estimate the gas cost for a transaction",
      {
        to: z.string().describe("The recipient address"),
        value: z
          .string()
          .optional()
          .describe("The amount of ETH to send in ether (e.g., '0.1')"),
        data: z
          .string()
          .optional()
          .describe("The transaction data as a hex string"),
        network: defaultNetworkParam
      },
      async ({ to, value, data, network }) => {
        try {
          const params: any = { to: to as Address }
    
          if (value) {
            params.value = services.helpers.parseEther(value)
          }
    
          if (data) {
            params.data = data as `0x${string}`
          }
    
          const gas = await services.estimateGas(params, network)
    
          return mcpToolRes.success({
            network,
            estimatedGas: gas.toString()
          })
        } catch (error) {
          return mcpToolRes.error(error, "estimating gas")
        }
      }
    )
  • Supporting helper function that performs the actual gas estimation using the viem public client for the specified network and transaction parameters.
    export async function estimateGas(
      params: EstimateGasParameters,
      network = "ethereum"
    ): Promise<bigint> {
      const client = getPublicClient(network)
      return await client.estimateGas(params)
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states the basic function without behavioral details. It doesn't disclose if this is a read-only operation (implied but not explicit), whether it requires network access, potential rate limits, error conditions, or what the output looks like (e.g., gas units or cost in currency).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's front-loaded and wastes no space, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of gas estimation in blockchain contexts, no annotations, and no output schema, the description is insufficient. It lacks details on return values (e.g., gas limit vs. gas price), network-specific behaviors, or error handling, leaving significant gaps for an agent to operate effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all parameters (data, network, to, value). The description adds no additional meaning beyond the schema's details, such as explaining parameter interactions or default behaviors, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('estimate') and resource ('gas cost for a transaction'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from siblings like 'get_transaction' or 'write_contract' that might also involve gas considerations, which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing transaction details), contrast with siblings (e.g., 'write_contract' for actual execution), or specify use cases (e.g., pre-execution planning), leaving the agent with minimal context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related 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/bnb-chain/bnbchain-mcp'

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