Library Extraction Recommendation Tool
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
Library Extraction Recommendation Tool analyzes smart contract bytecode, ABIs, and function purity to recommend extracting reusable utility functions into separate libraries. It retrieves on-chain contract bytecode via eth_getCode and fetches verified source code and ABI from block explorer APIs to extract function signatures, state variable dependencies, and modifier structures. The tool performs a comprehensive purity analysis, classifying each function as view, pure, or state-mutating based on its access to contract state. It then evaluates candidate functions for library extraction using multiple criteria: purity (pure/view functions are ideal candidates), reusability potential (functions with generic logic that could be used across multiple contracts), size impact (functions that contribute significantly to bytecode size), and dependency independence (functions that don't depend on contract-specific state). The output includes a list of suggested library candidates with estimated size reduction, purity classifications, and a score indicating extraction suitability, along with actionable recommendations for refactoring.
HOW TO USE
Connect your BGWallet to the target EVM chain. Paste the address of the contract you wish to analyze for library extraction opportunities. Optionally supply a GitHub repository URL to pull existing library definitions, upgrade documentation, or extraction patterns for additional context. The tool fetches the contract's bytecode and ABI, performs purity analysis on all functions, and evaluates each function's suitability for library extraction. Review the suggested library candidates, their purity classifications, and the estimated size reduction. Use the recommendations to guide refactoring efforts, extracting pure and view functions into shared libraries that can be deployed once and reused across multiple contracts, reducing overall deployment costs and improving maintainability.
PURITY AND REUSABILITY SCORING ENGINE
The real technical mechanism is the purity and reusability scoring engine that combines static analysis with pattern recognition. The tool first performs a precise purity analysis on every function by examining its ABI and source code, classifying functions as pure (no state access), view (reads state but doesn't modify it), or mutating (modifies state). Pure and view functions are given higher extraction scores because they don't depend on contract state and can be easily moved to libraries. The tool then analyzes each function's parameter types and internal logic using pattern matching against a library of common utility patterns—mathematical operations, string manipulations, validation checks, conversion functions, and cryptographic operations. Functions that match these patterns receive additional scoring weight, as they are likely to be reusable across multiple contracts. The engine also estimates the bytecode size contribution of each candidate function and computes a potential size reduction if extracted. The scoring algorithm combines these factors: purity (40% weight), reusability pattern match (30%), size impact (20%), and dependency independence (10%), producing a final extraction suitability score from 0-100. This approach automates what is traditionally a manual architectural decision, reducing the effort required to identify library extraction opportunities from hours to seconds and improving contract modularity and gas efficiency.
WHAT IT CANNOT SEE
This tool cannot recommend library extraction without access to contract bytecode or ABI. It is limited by your RPC provider's rate limits for bytecode retrieval, which may delay analysis on congested networks. It cannot detect logic that is better left in the main contract due to gas optimization—for example, functions that are called frequently and benefit from internal direct calls (which are cheaper than library calls) should remain in the main contract. The recommendations rely on the completeness of the ABI and source code verification; unverified contracts or incomplete verification data will produce incomplete or inaccurate suggestions. Recommendations are based on structural analysis and may not capture all semantic nuances, such as functions that appear pure but have hidden dependencies on contract-specific constants or assumptions. The tool cannot assess the quality or appropriateness of proposed library boundaries—it suggests candidates based on purity and patterns, but these may not align with the intended architecture or upgrade strategy. It may produce false positives for functions that are used in multiple contexts but should remain internal for security or upgradeability reasons. The tool does not execute the contract to validate extraction recommendations; all suggestions should be reviewed in the context of the contract's security model and upgrade strategy. It cannot account for deployment costs or gas optimization trade-offs between deploying a library versus keeping functions in the main contract, particularly for contracts that are already near the size limit.
PLEASE NOTE
This tool works exclusively with EVM-compatible chains. It requires active internet connectivity to access block explorer APIs and RPC endpoints. Some block explorers may require API keys for high-volume bytecode retrieval. The tool is read-only and does not modify or deploy any code—it only produces analysis and recommendations. Always review library extraction recommendations against your specific contract's logic, security requirements, and upgrade strategy before refactoring production contracts.