Skip to main content

Solc-Parser

A powerful Solidity compiler (solc) version management tool that automatically parses Solidity files and installs the appropriate solc version based on pragma statements and version requirements.

Features

  • Automatic Version Detection: Parses Solidity files to extract version requirements from pragma statements
  • Complete npm Semver Support: Full implementation of npm semantic versioning rules including:
    • Caret ranges (^1.2.3)
    • Tilde ranges (~1.2.3)
    • Hyphen ranges (1.2.3 - 2.3.4)
    • X-ranges (1.2.x, 1.x, *, 0.8.*)
    • Comparison operators (>=, <=, >, <, =)
    • Logical OR (||)
    • Prerelease tags (1.2.3-alpha.1)
    • Build metadata (1.2.3+build.1)
  • Advanced Pragma Support: Parses and handles:
    • pragma solidity version ranges
    • pragma abicoder v1/v2
    • pragma experimental ABIEncoderV2, SMTChecker
  • Automatic Installation: Downloads and installs solc binaries from official sources
  • Global Version Management: Creates symbolic links for easy version switching
  • Cross-Platform Support: Works on Linux and macOS
  • PATH Integration: Provides instructions for PATH setup

Installation

From Source

git clone https://github.com/siksum/Solc-Parser.git
cd Solc-Parser
pip install -e .

Using pip

pip install solc-parser

Usage

Basic Usage

Parse a Solidity file and automatically install the appropriate solc version:

solc-parser your_contract.sol

Command Line Options

# List all available solc versions
solc-parser --list

# Install specific version(s)
solc-parser --install 0.8.30
solc-parser --install 0.7.*  # Install latest 0.7.x version

# Use specific version
solc-parser --use 0.8.30
solc-parser --use 0.7.*  # Use latest 0.7.x version

# Uninstall version(s)
solc-parser --uninstall 0.7.6

# Show current version
solc-parser --version

Examples

Simple Solidity File

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimpleContract {
    uint256 public value;
    
    function setValue(uint256 _value) external {
        value = _value;
    }
}

Running solc-parser simple.sol will:

  1. Parse the pragma statement ^0.8.0
  2. Find the latest compatible version (e.g., 0.8.30)
  3. Download and install solc 0.8.30
  4. Create a symbolic link for global use

Advanced Solidity File with Multiple Pragmas

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v2;
pragma experimental SMTChecker;

contract AdvancedContract {
    struct ComplexStruct {
        uint256[] numbers;
        string name;
    }
    
    function processData(ComplexStruct memory data) external pure returns (uint256) {
        return data.numbers.length;
    }
}

Running solc-parser advanced.sol will:

  1. Parse all pragma statements
  2. Determine version requirements:
    • ^0.8.0 (solidity version)
    • >=0.5.0 (abicoder v2 requirement)
    • >=0.5.0 (SMTChecker requirement)
  3. Find the best matching version that satisfies all requirements
  4. Install and configure the appropriate solc version

Version Range Support

Caret Ranges (^)

  • ^1.2.3 := >=1.2.3 <2.0.0
  • ^0.2.3 := >=0.2.3 <0.3.0
  • ^0.0.3 := >=0.0.3 <0.1.0

Tilde Ranges (~)

  • ~1.2.3 := >=1.2.3 <1.3.0
  • ~1.2 := >=1.2.0 <1.3.0
  • ~1 := >=1.0.0 <2.0.0

X-Ranges

  • 1.2.x or 1.2.* := >=1.2.0 <1.3.0
  • 1.x or 1.* := >=1.0.0 <2.0.0
  • * or x := accepts all versions

Hyphen Ranges

  • 1.2.3 - 2.3.4 := >=1.2.3 <=2.3.4

Comparison Operators

  • >=1.2.3, <=1.2.3, >1.2.3, <1.2.3, =1.2.3

Logical OR

  • ^1.2.3 || ^2.3.4 := satisfies either range

Installation Directory

Solc binaries are installed in:

~/.solc-parser/bin/
├── solc-0.7.6/
│   └── solc
├── solc-0.8.30/
│   └── solc
└── solc -> solc-0.8.30/solc  # Symbolic link to current version

PATH Setup

After installation, add the binary directory to your PATH:

Temporary (current session only)

export PATH="$HOME/.solc-parser/bin:$PATH"

Permanent (bash)

echo 'export PATH="$HOME/.solc-parser/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Permanent (zsh)

echo 'export PATH="$HOME/.solc-parser/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Alternative: Use alias

echo "alias solc='$HOME/.solc-parser/bin/solc'" >> ~/.bashrc
source ~/.bashrc

Requirements

  • Python 3.8 or higher
  • Linux or macOS
  • Internet connection for downloading solc binaries

Dependencies

  • requests: For downloading solc binaries

Development

Building

./build.sh

Testing

python -m pytest tests/

License

This project is licensed under the GNU General Public License v3 (GPLv3) - see the LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Issues

If you encounter any issues, please report them on the GitHub Issues page.

Author

Namryeong Kim - GitHub

Acknowledgments

  • Solidity team for the official solc binaries
  • npm semver specification for version range parsing rules

Release files for solc-parser 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for solc-parser 1.1.0
File Size Uploaded
solc_parser-1.1.0.tar.gz 23.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for solc-parser 1.1.0
File Interpreter ABI Platform
solc_parser-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 47.8 kB

Release files / solc_parser-1.1.0.tar.gz

Download URL solc_parser-1.1.0.tar.gz
Size 23.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9319885605744d5f4866d349ba821f471a6aa6c8164c069be2734831e5a50ceb
BLAKE2b-256 checksum
How to use checksums
8854d8e8084bb6dfd422616505b25f9886958f16e7a3ffd31a45839b0aa84655
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / solc_parser-1.1.0-py3-none-any.whl

Download URL solc_parser-1.1.0-py3-none-any.whl
Size 24.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
704f2a0487324ca2589754267c96f20355093efc61bcec577d6a42af5a5d3555
BLAKE2b-256 checksum
How to use checksums
722a36c38fe92e4065110c46a35b1440010cf1765b42e5b6d499fad84528a401
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page