estimate_gas
Calculate transaction gas costs on multiple blockchains to optimize network fees before execution.
Instructions
Estimate gas required for a transaction
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blockchain | Yes | Blockchain name | |
| transaction | Yes | Transaction object with from, to, data, value, etc. | |
| network | No | Network type (defaults to mainnet) |
Implementation Reference
- The handler logic for the 'estimate_gas' tool. Extracts parameters from args and delegates to AdvancedBlockchainService.estimateGas, then formats the response as MCP content.case 'estimate_gas': { const blockchain = args?.blockchain as string; const transaction = args?.transaction as any; const network = (args?.network as 'mainnet' | 'testnet') || 'mainnet'; const result = await advancedBlockchain.estimateGas(blockchain, transaction, network); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], isError: !result.success, }; }
- Input schema definition for the 'estimate_gas' tool, specifying required blockchain, transaction object, and optional network.inputSchema: { type: 'object', properties: { blockchain: { type: 'string', description: 'Blockchain name', }, transaction: { type: 'object', description: 'Transaction object with from, to, data, value, etc.', }, network: { type: 'string', enum: ['mainnet', 'testnet'], description: 'Network type (defaults to mainnet)', }, }, required: ['blockchain', 'transaction'], },
- src/handlers/transaction-handlers.ts:62-84 (registration)Tool object registration for 'estimate_gas' returned by registerTransactionHandlers, including name, description, and schema. Added to global tools list in src/index.ts.{ name: 'estimate_gas', description: 'Estimate gas required for a transaction', inputSchema: { type: 'object', properties: { blockchain: { type: 'string', description: 'Blockchain name', }, transaction: { type: 'object', description: 'Transaction object with from, to, data, value, etc.', }, network: { type: 'string', enum: ['mainnet', 'testnet'], description: 'Network type (defaults to mainnet)', }, }, required: ['blockchain', 'transaction'], }, },
- Supporting method in AdvancedBlockchainService that performs the actual RPC call to 'eth_estimateGas' via the blockchain service.async estimateGas( blockchain: string, transaction: any, network: 'mainnet' | 'testnet' = 'mainnet' ): Promise<EndpointResponse> { const service = this.blockchainService.getServiceByBlockchain(blockchain, network); if (!service) { return { success: false, error: `Blockchain service not found: ${blockchain} (${network})`, }; } return this.blockchainService.callRPCMethod( service.id, 'eth_estimateGas', [transaction] ); }