External Call Gas Stipend Calculator
Free to download on every platform. Comes pre-installed on BotFone, BotPad and BotFlip — with extra free apps included.
About this app
WHAT IT DOES
External Call Gas Stipend Calculator is a read-only developer tool that analyzes EVM smart contract bytecode to detect external calls (CALL, STATICCALL, DELEGATECALL) and calculate recommended gas stipends. It scans contract bytecode for call opcodes, extracts the gas values passed to each call, identifies the function selector context, and evaluates whether the gas stipend is sufficient based on historical transaction data and opcode cost analysis. The tool provides actionable recommendations for gas limit adjustments, flags dangerously low gas stipends that could cause out-of-gas failures, and offers best-practice guidance for setting safe gas limits on external calls.
HOW TO USE
Connect your EVM-compatible wallet via the BGWallet bridge and select the network where your contract is deployed. Enter the contract address you want to analyze, optionally specify a target external contract address to filter calls, and click "Calculate Gas Stipend". The tool fetches contract bytecode, scans for external call opcodes using pattern matching (0xf1 for CALL, 0xfa for STATICCALL, 0xf4 for DELEGATECALL), extracts the gas parameters from preceding PUSH instructions, retrieves historical transaction data to calculate average gas usage, and generates a comprehensive stipend analysis. Results include detected call types, current gas stipend values, per-call recommendations, severity ratings (high/medium/low), historical gas statistics, and best-practice guidance. All analysis is read-only—no signatures or transactions are submitted.
TECHNICAL MECHANISM
The tool uses ethers.js v5.7.2 to fetch contract bytecode via provider.getCode(address), then performs static opcode analysis to detect external call instructions. It scans bytecode hex for CALL (0xf1), STATICCALL (0xfa), and DELEGATECALL (0xf4) opcodes, and for each detection, looks backward up to 40 bytes to find the preceding PUSH instruction (opcodes 0x60-0x7F) that provides the gas parameter. The gas value is extracted and parsed as a number or hex string. The tool also extracts the function selector by scanning backward 60 bytes for the PUSH4 opcode (0x63) pattern to identify which function makes the call. Historical transaction data is fetched using chunked log scanning that automatically halves request ranges if RPCs reject full-range queries, retrieving up to 30 recent transactions and calculating average gas used. Each detected call is evaluated against thresholds: gas stipends below 10,000 are flagged as high severity, between 10,000 and 50,000 as medium severity, and above 50,000 as low severity. Recommendations are generated based on the gas value and historical context, with best-practice guidance including using explicit gas limits, ensuring at least 50,000 gas for simple calls and 100,000+ for complex calls, implementing gasleft() checks, and maintaining safety margins.
WHAT IT CANNOT SEE
This tool has fundamental limitations that users must understand. It cannot predict exact gas consumption of external calls without executing them or simulating with specific inputs—gas costs depend on the called contract's internal logic and the current state of the EVM. It cannot account for gas costs of the called contract's internal logic that depends on runtime state—the called contract may execute different code paths with vastly different gas costs based on storage values or caller identity. It cannot analyze calls to non-contract addresses or precompiles with fixed gas costs—calls to EOAs or precompiles like ecrecover have known gas costs that the tool does not specifically model. It cannot determine if a call will revert or consume more gas due to edge cases not present in historical data—unusual inputs or state conditions may cause the called contract to consume far more gas than observed historically. It cannot simulate actual EVM execution, so it does not account for cold storage access costs, memory expansion costs, or gas refunds. The tool's gas stipend recommendations are estimates and should be validated with actual execution testing. It cannot analyze contracts that are not deployed or that have no bytecode.
PLEASE NOTE
This tool only supports EVM-compatible blockchains (Ethereum, Polygon, BSC, Avalanche C-Chain, Optimism, Arbitrum, and their testnets). Solana, Tron, Starknet, SUI, TON, Aptos, Bitcoin, Cosmos, and XRP are not supported. The tool is free, open-source, requires no API keys, and uses the wallet's native provider for all read operations. Always validate gas stipend recommendations with thorough testing on testnets before deploying to production.