estimate_gas
Calculate the gas needed for blockchain transactions to optimize costs and ensure successful execution across multiple networks.
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
- Handler logic for the 'estimate_gas' tool: extracts parameters from args, calls advancedBlockchain.estimateGas, and returns formatted 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, }; }
- Input schema definition for the 'estimate_gas' tool, specifying parameters and validation.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 registration object for 'estimate_gas' returned by registerTransactionHandlers function.{ 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'], }, },
- Core implementation of estimateGas: retrieves blockchain service and calls RPC 'eth_estimateGas' method.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] ); }