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.
- 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
)
- Caret ranges (
- Advanced Pragma Support: Parses and handles:
pragma solidity
version rangespragma 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
git clone https://github.com/siksum/Solc-Parser.git
cd Solc-Parser
pip install -e .
pip install solc-parser
Parse a Solidity file and automatically install the appropriate solc version:
solc-parser your_contract.sol
# 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
// 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:
- Parse the pragma statement
^0.8.0
- Find the latest compatible version (e.g., 0.8.30)
- Download and install solc 0.8.30
- Create a symbolic link for global use
// 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:
- Parse all pragma statements
- Determine version requirements:
^0.8.0
(solidity version)>=0.5.0
(abicoder v2 requirement)>=0.5.0
(SMTChecker requirement)
- Find the best matching version that satisfies all requirements
- Install and configure the appropriate solc version
^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
~1.2.3
:=>=1.2.3 <1.3.0
~1.2
:=>=1.2.0 <1.3.0
~1
:=>=1.0.0 <2.0.0
1.2.x
or1.2.*
:=>=1.2.0 <1.3.0
1.x
or1.*
:=>=1.0.0 <2.0.0
*
orx
:= accepts all versions
1.2.3 - 2.3.4
:=>=1.2.3 <=2.3.4
>=1.2.3
,<=1.2.3
,>1.2.3
,<1.2.3
,=1.2.3
^1.2.3 || ^2.3.4
:= satisfies either range
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
After installation, add the binary directory to your PATH:
export PATH="$HOME/.solc-parser/bin:$PATH"
echo 'export PATH="$HOME/.solc-parser/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
echo 'export PATH="$HOME/.solc-parser/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
echo "alias solc='$HOME/.solc-parser/bin/solc'" >> ~/.bashrc
source ~/.bashrc
- Python 3.8 or higher
- Linux or macOS
- Internet connection for downloading solc binaries
requests
: For downloading solc binaries
./build.sh
python -m pytest tests/
This project is licensed under the GNU General Public License v3 (GPLv3) - see the LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
If you encounter any issues, please report them on the GitHub Issues page.
Namryeong Kim - GitHub
- Solidity team for the official solc binaries
- npm semver specification for version range parsing rules