forge-scriptgen is a CLI that generates Foundry deployment scripts (*.s.sol) from Solidity source files in a Foundry project. It scans src/**/*.sol, finds deployable contracts, extracts constructor signatures, and emits ready-to-edit scripts under script/.
Foundry is fast because it keeps the deployment loop close to the code. The missing piece in many teams is the repetitive glue work between contract discovery and script authoring. forge-scriptgen removes that manual step.
For global Foundry users, the value is straightforward:
- faster first deployment for new contracts
- fewer copy-paste mistakes in constructor calls
- better consistency across teams and repositories
- a CLI workflow that fits directly into existing Foundry projects
For Foundry maintainers, this project is useful because it explores a practical layer on top of Foundry without changing Foundry itself:
- it validates demand for script generation as a developer workflow
- it provides concrete fixtures for complex Solidity parsing cases
- it offers a small Rust codebase for experimenting with parser backends before deeper ecosystem integration
This project is worth using if you want a lightweight tool that turns contract source into a deployment-script starting point quickly, especially in repositories with many contracts, frequent constructor changes, or multiple contributors.
- Discovers deployable contracts from
src/**/*.sol - Selects contracts by contract name, relative path, or file name
- Generates
script/<ContractName>.s.solby default - Accepts constructor arguments through JSON or interactive prompts
- Supports raw Solidity literals for complex constructor values
- Lists detected contracts and constructor signatures with
--list - Prevents overwriting existing scripts unless
--forceis provided
The current parser backend is string-walker. It is structured behind a parser abstraction so an AST backend can be added later without rewriting the CLI flow.
The current test and fixture coverage includes:
- abstract contracts
- inheritance-based constructor modifiers
- multiline constructors
structconstructor arguments- function-typed constructor arguments
errordeclarations- inline
assembly - misleading
contractandconstructortext inside comments and strings
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"git clone https://github.com/kimh4nkyul/forge-scriptgen.git
cd forge-scriptgencargo install --path .Or build and run locally:
cargo build --release
./target/release/forge-scriptgen --helpRun the CLI from the root of a Foundry project.
forge-scriptgen --helpforge-scriptgen --parser string-walker --listforge-scriptgen --args '["0xDeAd", 42]' --private-key 0xabc123 CounterUse {"raw":"..."} or {"solidity":"..."} when a value must stay as a Solidity literal rather than a JSON string.
forge-scriptgen \
--parser string-walker \
--args '[{"raw":"Config({owner: msg.sender, limits: [1, 2, 3]})"},{"raw":"callback"},"primary",{"raw":"hex\"1234\""}]' \
--private-key 0xabc123 \
ComplexDeploymentforge-scriptgen Counterforge-scriptgen --force CounterGenerated scripts are written to script/<ContractName>.s.sol by default. Use --output-dir to change the destination. Import paths are computed relative to the generated script location.
The repository includes a reproducible fixture for complex Solidity parsing and generation:
./scripts/reproduce_complex_cli_demo.shThis script:
- prints the Solidity fixture contracts
- runs
forge-scriptgenon them - prints the generated
.s.solfiles - verifies the generated output against committed expected files
Reference files:
tests/fixtures/repro/src/tests/fixtures/repro/expected/scripts/reproduce_complex_cli_demo.sh
If you want to improve parsing coverage, CLI UX, fixtures, or generation quality, start here:
The fastest contributor loop is:
cargo fmt
cargo test
./scripts/reproduce_complex_cli_demo.sh--private-key embeds the private key literal directly into the generated script. Do not commit generated scripts that contain real keys. Use disposable values for local testing, or extend the workflow to environment-based key loading before using it in production.
cargo fmt
cargo test
cargo run -- --help
cargo run -- --parser string-walker --listAfter generation, continue with standard Foundry commands such as forge test or forge script.