You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Scripts as CI and ops tools: how do you pass parameters and return results?
#18117
Many projects use forge script beyond deployments: CI checks, config syncs, runbooks. They need parameters from the caller and a result the caller can act on. I'd like to learn what the intended pattern is and how others handle it today.
What exists (checked on 1.8.1)
--sig: --sig 'run((address,uint256)[])' '[(0x…,1e18)]' is typed, accepts structs and arrays, and is checked before the run. Arguments are positional, with no names and no defaults.
--json: run() return values appear under .returns. A revert gives "success": false and the raw revert data in .returned; the decoded reason is only on stderr. Every script failure exits with 1.
What this looks like in practice
From one production deployment repo we studied (pinned to 1.8.1):
Parameters through the environment: 31 Make targets turn command-line arguments into 63 environment keys, read by 184 vm.env* calls. The Makefile also has 37 lines of required-argument guards.
Exit codes through grep: a CI check needs three outcomes (in sync, drift, error). The script can only return or revert, so a wrapper greps forge's stderr for the revert text. A failure passes through HTTP status, shell exit code, stderr, revert string, forge stderr and then grep. That is about 460 lines including tests.
Several entry points: one script exposes init, run, preview and check, each selected with --sig.
Returning a verdict from run() and reading it with --json removes the grep, not the wrapper.
What Hardhat does
Hardhat 3 tasks declare named, typed options with defaults, plus positional arguments and flags (addOption({ name, type: ArgumentType.INT, defaultValue })). Hardhat parses and validates them. A task action can return a Result, and a failed result sets exit code 1 (writing tasks, task options).
Hardhat Ignition takes a JSON parameters file per deployment (--parameters ignition/parameters.json, with per-module and $global keys) (docs).
hardhat run scripts take no arguments either, so in Hardhat the typed path is tasks, not scripts.
Context
We proposed --arg NAME=VALUE (#17973) and a vm.setExitCode cheatcode (#17975). Both were closed: --sig, vm.envOr and --json cover the base case, and a new flag or cheatcode is a long-term commitment. That is a reasonable call; this thread is not about reopening them, but about whether others hit the same limits and what they do about them.
Earlier threads on the same theme: #2456 (passing data to forge script) and #4468 (good script patterns).
Questions
Is --sig + vm.envOr + --json the intended pattern for scripts used as tools, or is there a better one?
If you run scripts from CI or Make, what does your wrapper do? Shell + jq, just, a TypeScript runner, something else?
Which limit costs you the most: named arguments, defaults, distinct exit codes, the decoded revert reason in --json, or something not listed?
Please share your workaround, even a short one. A 👍 on this post or on a comment helps show how common each case is.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Many projects use
forge scriptbeyond deployments: CI checks, config syncs, runbooks. They need parameters from the caller and a result the caller can act on. I'd like to learn what the intended pattern is and how others handle it today.What exists (checked on 1.8.1)
--sig:--sig 'run((address,uint256)[])' '[(0x…,1e18)]'is typed, accepts structs and arrays, and is checked before the run. Arguments are positional, with no names and no defaults.vm.env*/vm.envOr: named, with defaults. A misspelled key silently returns the default. Before 1.8.5 a malformed value did too (fixed in fix(cheatcodes): surface parse errors from envOr #16924).--json:run()return values appear under.returns. A revert gives"success": falseand the raw revert data in.returned; the decoded reason is only on stderr. Every script failure exits with 1.What this looks like in practice
From one production deployment repo we studied (pinned to 1.8.1):
vm.env*calls. The Makefile also has 37 lines of required-argument guards.grep. That is about 460 lines including tests.init,run,previewandcheck, each selected with--sig.Returning a verdict from
run()and reading it with--jsonremoves the grep, not the wrapper.What Hardhat does
addOption({ name, type: ArgumentType.INT, defaultValue })). Hardhat parses and validates them. A task action can return aResult, and a failed result sets exit code 1 (writing tasks, task options).--parameters ignition/parameters.json, with per-module and$globalkeys) (docs).hardhat runscripts take no arguments either, so in Hardhat the typed path is tasks, not scripts.Context
We proposed
--arg NAME=VALUE(#17973) and avm.setExitCodecheatcode (#17975). Both were closed:--sig,vm.envOrand--jsoncover the base case, and a new flag or cheatcode is a long-term commitment. That is a reasonable call; this thread is not about reopening them, but about whether others hit the same limits and what they do about them.Earlier threads on the same theme: #2456 (passing data to
forge script) and #4468 (good script patterns).Questions
--sig+vm.envOr+--jsonthe intended pattern for scripts used as tools, or is there a better one?--json, or something not listed?Please share your workaround, even a short one. A 👍 on this post or on a comment helps show how common each case is.
All reactions