All Projects → BlockCatIO → Solidity Flattener

BlockCatIO / Solidity Flattener

Licence: mit
A python utility to flatten Solidity code with imports into a single file.

Programming Languages

python
139335 projects - #7 most used programming language
solidity
1140 projects

Solidity Flattener

A BlockCAT Technologies contribution - https://blockcat.io

Are you tired of having to manually combine all of your files when verifying your contract source on Etherscan? This script automatically traverses the dependency graph and outputs all of your imports in the correct order, ready to be pasted into the contract verifier.

This is also useful for quickly throwing your source into Remix without having to fumble with local filesystem connections.

NOTE: This script does not work with imports that are aliased (i.e. import './A.sol' as B; ).

Requirements

  • Python 3.5+, pip
  • solc, the Solidity compiler
    • Note: The NPM version of the compiler does not expose enough functionality to satisfy the requirements of this tool.

Installation

pip install solidity-flattener

Usage

usage: solidity_flattener [-h] [--output FILENAME] [--solc-paths SOLC_PATHS]
                          target_solidity_file

Flattens a target Solidity source file by resolving all of its imports and
dependencies. NOTE: This does not work with imports that are aliased (i.e.
import './A.sol' as B; )

positional arguments:
  target_solidity_file  Specifies the target Solidity source file to flatten.

optional arguments:
  -h, --help            show this help message and exit
  --output FILENAME     Specifies the output destination filename. Outputs to
                        stdout by default.
  --solc-paths SOLC_PATHS
                        Specifies the path replacements to pass onto solidity.
                        See solc --help for more information.

Examples

To flatten a Solidity file:

solidity_flattener StandardToken.sol

To output to a file instead of standard out:

solidity_flattener --output StandardTokenFlattened.sol StandardToken.sol

To provide import path redirections:

solidity_flattener --solc-paths="my_solidity_path=my_actual_path" StandardToken.sol

Contributions

Pull requests are welcome, or feel free to open an issue to discuss.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].