npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

solidity-gas-optimizer

v0.1.2

Published

CLI tool for detecting gas optimization opportunities in Solidity code

Readme

🚀 Solidity Gas Optimizer

npm version License: MIT

A powerful CLI tool that analyzes Solidity smart contracts to detect gas optimization opportunities. Save thousands in gas fees by identifying and fixing common inefficient patterns.

✨ Features

  • 🔍 Storage Read in Loops - Detect expensive storage reads inside loops
  • 🔐 Public vs External - Identify functions that should be external instead of public
  • 📦 State Variable Packing - Find inefficient variable ordering that wastes storage slots
  • 🚨 Custom Errors - Suggest replacing string reverts with gas-efficient custom errors
  • 🎨 Beautiful Output - Color-coded results with detailed suggestions
  • Fast Analysis - Powered by AST parsing for accurate detection

📊 Real Impact

// Before optimization: 103,320 gas
contract Unoptimized {
    uint128 a;      // slot 0 (wasted 128 bits)
    uint256 b;      // slot 1
    uint128 c;      // slot 2 (wasted 128 bits)
    
    function sum() public view returns (uint256) {
        uint256 total = 0;
        for (uint i = 0; i < array.length; i++) {  // 100 gas per iteration
            total += array[i];
        }
        return total;
    }
}

// After optimization: 23,420 gas (77% savings!)
contract Optimized {
    uint256 b;      // slot 0
    uint128 a;      // slot 1
    uint128 c;      // slot 1 (packed!)
    
    function sum() external view returns (uint256) {
        uint256 total = 0;
        uint256 length = array.length;  // Cache length
        for (uint i = 0; i < length; i++) {
            total += array[i];
        }
        return total;
    }
}

🛠️ Installation

Global Installation (Recommended)

npm install -g solidity-gas-optimizer

Local Installation

npm install --save-dev solidity-gas-optimizer

🚀 Quick Start

Basic Usage

# Analyze a single file
gas-opt analyze contracts/Token.sol

# Analyze with specific rules
gas-opt analyze contracts/Token.sol --rules storage-read-in-loop,custom-errors

# List all available rules
gas-opt analyze --list-rules

Example Output

╔═══════════════════════════════════════════════════╗
║          Solidity Gas Optimization Tool           ║
╚═══════════════════════════════════════════════════╝

✓ Analyzing: Token.sol

🔍 Gas Optimization Report

🔄 Storage Reads in Loops (2 issues)
──────────────────────────────────────────────────

[1] 🔴 HIGH at line 45
    Storage array length 'balances.length' is being read inside a loop condition

      45 │ for (uint i = 0; i < balances.length; i++) {
              ╰── here

    💡 Suggestion: Cache the array length before the loop:
       uint256 balancesLength = balances.length;
    ⛽ Gas Impact: ~2100 gas per iteration

📊 Summary Report
══════════════════════════════════════════════════
  Severity Distribution:
    High    │ ████████ 4
    Medium  │ ████ 2
    
  Optimization Score: 73/100

📋 Available Rules

| Rule | Description | Impact | |------|-------------|---------| | storage-read-in-loop | Detects storage variables read inside loops | HIGH | | public-vs-external | Suggests using external for non-internal functions | MEDIUM | | state-variable-packing | Identifies inefficient variable ordering | HIGH | | use-custom-errors | Replaces string reverts with custom errors | MEDIUM |

🤝 Contributing

We love contributions! See CONTRIBUTING.md for guidelines.

Adding New Rules

  1. Create a new rule in src/rules/
  2. Extend the BaseRule class
  3. Add to rule registry
  4. Submit a PR!

📈 Roadmap

  • [x] Core rules implementation
  • [x] Beautiful CLI output
  • [ ] Config file support (v0.2.0)
  • [ ] Auto-fix capability (v0.3.0)
  • [ ] VS Code extension (v0.4.0)
  • [ ] More optimization rules (ongoing)

📄 License

MIT © I'ts Beerz