Skip to content

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

License

Notifications You must be signed in to change notification settings

mixbytes/solidity-flattener

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.
                        Can be specified multiple times. See solc --help for
                        more information.
  --solc-allow-paths SOLC_ALLOW_PATHS
                        Specifies allowed paths for solidity imports. 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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 97.0%
  • Shell 3.0%