Compile Smart Contracts Script
python3 compile_smart_contracts.py [--compile | --clean | --add CONTRACT_PATH.sol] A command-line utility for managing the lifecycle of Solidity smart contracts within the Maroo repository. It handles discovery, compilation via Hardhat, and distribution of compiled artifacts. This script is the primary tool for updating contract ABIs used by the core Go modules.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
--compile | flag | - | The default action. Scans the repository for all relevant .sol files, copies them to the Hardhat project, compiles them, and copies the resulting JSON artifacts back to their source directories. |
--clean | flag | - | Removes all build artifacts and temporary files. This includes the contracts/solidity, contracts/artifacts, contracts/cache, and contracts/node_modules directories. |
--add CONTRACT_PATH.sol | flag | - | Recompiles a single specified contract and updates its JSON artifact. This is much faster than a full recompile and is useful when iterating on a single contract interface. The path can be relative to the repository root. |
Returns
void This script does not return a value. It prints status messages to standard output and exits with a non-zero status code on error.
Errors
| Code | Name | Description |
|---|---|---|
1 | CompilationError | Occurs if the Hardhat compilation process fails due to Solidity syntax errors, unresolved imports, or other compiler issues. |
1 | FileNotFoundError | Occurs when using `--add` if the specified contract path does not exist. |
Examples
Perform a full recompile
This is the most common use case. It ensures all contract artifacts in the repository are up-to-date with their source files.
# Navigate to the scripts directory
cd scripts/compile_smart_contracts
# Run the compilation script
python3 compile_smart_contracts.py --compile Update a single contract's ABI
Use the `--add` flag for a fast, targeted update after changing a specific contract. This avoids the overhead of recompiling the entire contract suite.
# After modifying the PCL interface, update only its artifact
cd scripts/compile_smart_contracts
python3 compile_smart_contracts.py --add precompiles/pcl/IPcl.sol Clean the build environment
This command is useful for starting from a clean slate, resolving caching issues, or before archiving the repository.
# Remove all generated files and dependencies
cd scripts/compile_smart_contracts
python3 compile_smart_contracts.py --clean