estimate_gas
Calculate gas costs for blockchain transactions before execution to manage fees and avoid failed transactions across multiple networks.
Instructions
Estimate gas required for a transaction
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blockchain | Yes | Blockchain name | |
| network | No | Network type (defaults to mainnet) | |
| transaction | Yes | Transaction object with from, to, data, value, etc. |
Implementation Reference
- src/handlers/transaction-handlers.ts:61-83 (registration)Tool registration for 'estimate_gas' including name, description, and input schema definition.{ 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'], }, },
- MCP tool handler logic for 'estimate_gas': parses arguments, calls service method, formats response.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, }; }
- Supporting service method that performs the actual gas estimation via RPC call to 'eth_estimateGas'.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] ); }