Skip to main content
Glama

Rootstock MCP Server

by cuongpo

estimate_gas

Calculate the gas cost for transactions on the Rootstock blockchain by providing recipient address, optional value, and transaction data to optimize block space usage.

Instructions

Estimate gas cost for a transaction

Input Schema

NameRequiredDescriptionDefault
dataNoOptional transaction data
toYesRecipient address
valueNoOptional value to send (in ether)

Input Schema (JSON Schema)

{ "properties": { "data": { "description": "Optional transaction data", "type": "string" }, "to": { "description": "Recipient address", "type": "string" }, "value": { "description": "Optional value to send (in ether)", "type": "string" } }, "required": [ "to" ], "type": "object" }

Implementation Reference

  • Primary handler for the 'estimate_gas' MCP tool. Calls RootstockClient.estimateGas with parameters and returns formatted text response with gas limit, price, and estimated cost.
    private async handleEstimateGas(params: EstimateGasParams) { try { const estimate = await this.rootstockClient.estimateGas( params.to, params.value, params.data ); return { content: [ { type: 'text', text: `Gas Estimate:\n\nGas Limit: ${estimate.gasLimit}\nGas Price: ${estimate.gasPrice} wei\nEstimated Cost: ${estimate.estimatedCost} ${this.rootstockClient.getCurrencySymbol()}`, }, ], }; } catch (error) { throw new Error(`Failed to estimate gas: ${error}`); } }
  • src/index.ts:294-314 (registration)
    Tool registration in getAvailableTools(), including name, description, and input schema for 'estimate_gas'.
    { name: 'estimate_gas', description: 'Estimate gas cost for a transaction', inputSchema: { type: 'object', properties: { to: { type: 'string', description: 'Recipient address', }, value: { type: 'string', description: 'Optional value to send (in ether)', }, data: { type: 'string', description: 'Optional transaction data', }, }, required: ['to'], },
  • TypeScript interface defining input parameters for the estimate_gas tool.
    export interface EstimateGasParams { to: string; value?: string; data?: string; }
  • Core implementation in RootstockClient that performs the actual gas estimation using ethers.js provider. Computes gas limit, price, and total estimated cost.
    async estimateGas(to: string, value?: string, data?: string): Promise<GasEstimate> { try { const tx: ethers.TransactionRequest = { to, value: value ? ethers.parseEther(value) : 0, data: data || '0x', }; const [gasLimit, feeData] = await Promise.all([ this.getProvider().estimateGas(tx), this.getProvider().getFeeData(), ]); const gasPrice = feeData.gasPrice || BigInt(0); const estimatedCost = gasLimit * gasPrice; return { gasLimit: gasLimit.toString(), gasPrice: gasPrice.toString(), estimatedCost: ethers.formatEther(estimatedCost), }; } catch (error) { throw new Error(`Failed to estimate gas: ${error}`); } }
  • Alternative handler and registration for 'estimate_gas' in the Smithery server variant.
    server.tool( "estimate_gas", "Estimate gas cost for a transaction", { to: z.string().describe("Recipient address"), value: z.string().optional().describe("Optional value to send (in ether)"), data: z.string().optional().describe("Optional transaction data"), }, async ({ to, value, data }) => { try { const gasEstimate = await rootstockClient.estimateGas(to, value, data); return { content: [ { type: "text", text: `Gas Estimation:\n\nEstimated Gas: ${gasEstimate.gasLimit}\nGas Price: ${gasEstimate.gasPrice}\nEstimated Cost: ${gasEstimate.estimatedCost} ${rootstockClient.getCurrencySymbol()}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error estimating gas: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );

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/cuongpo/rootstock-mcp'

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