get_gas_price
Retrieve current gas prices for blockchain transactions on networks like Ethereum, Solana, Cosmos, and Sui. Specify blockchain and network type to get accurate fee data for transaction planning.
Instructions
Get current gas price for a blockchain
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blockchain | Yes | Blockchain name | |
| network | No | Network type (defaults to mainnet) |
Implementation Reference
- Core handler function that fetches the current gas price using the blockchain RPC eth_gasPrice method, handles EVM-compatible chains, converts values to Gwei and Wei, and returns formatted response.async getGasPrice( blockchain: string, 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})`, }; } const result = await this.blockchainService.callRPCMethod( service.id, 'eth_gasPrice', [] ); if (result.success && result.data) { const gasWei = BigInt(result.data); const gasGwei = Number(gasWei) / 1e9; return { success: true, data: { gasPrice: gasGwei, gasPriceWei: gasWei.toString(), gasPriceHex: result.data, }, metadata: result.metadata, }; } return result; }
- src/handlers/multichain-handlers.ts:65-83 (registration)Tool registration definition including name, description, and input schema for the MCP server.{ name: 'get_gas_price', description: 'Get current gas price for a blockchain', inputSchema: { type: 'object', properties: { blockchain: { type: 'string', description: 'Blockchain name', }, network: { type: 'string', enum: ['mainnet', 'testnet'], description: 'Network type (defaults to mainnet)', }, }, required: ['blockchain'], }, },
- Input schema defining parameters for the get_gas_price tool: blockchain (required), network (optional).inputSchema: { type: 'object', properties: { blockchain: { type: 'string', description: 'Blockchain name', }, network: { type: 'string', enum: ['mainnet', 'testnet'], description: 'Network type (defaults to mainnet)', }, }, required: ['blockchain'], },
- Dispatcher in handleMultichainTool that extracts arguments, calls the service handler, and formats MCP response.case 'get_gas_price': { const blockchain = args?.blockchain as string; const network = (args?.network as 'mainnet' | 'testnet') || 'mainnet'; const result = await advancedBlockchain.getGasPrice(blockchain, network); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], isError: !result.success, }; }