feat(script): propose a script's broadcast to a Safe (`--safe`)
Component
Forge (script)
Describe the feature you would like
Revisiting #1232 now that cast has a Safe client (#16377).
Teams whose contracts are owned by a Safe cannot run an admin or upgrade script against it. Today they run the script, then copy each transaction's calldata into the Safe UI or cast safe propose one at a time, or they use third-party libraries that shell out through vm.ffi (safe-utils, forge-safe, treb).
#1232 (16 👍) was closed in June 2025 as out of scope and solved by those libraries. Since then #16377 added cast safe (create, propose, sign, simulate, execute), with a Transaction Service client and SafeTx signing. So Foundry now has the pieces, and the remaining step is letting a script use them.
Proposal:
forge script script/Upgrade.s.sol --rpc-url mainnet --safe 0xSafe --account proposer --broadcast
- The script runs as today, broadcasting from the Safe:
vm.startBroadcast(0xSafe). In this mode an address without a key is accepted. - On
--broadcast, instead of sending, forge batches the recorded transactions into oneMultiSendCallOnlycall (or a plain call when there is one transaction). - It computes the SafeTx hash with the Safe's current nonce, signs it with the proposer (
--account, Ledger, keystore, ...) and proposes it to the Transaction Service, reusing thecast safecode. It prints the SafeTx hash and the Safe UI link. - The broadcast file records the proposal (Safe, nonce, SafeTx hash) instead of receipts.
Limits:
- A Safe cannot
CREATEfrom a MultiSend batch. Deployments would go through CREATE2 (the script'screate2_deployer); a plainnewin Safe mode fails with a message saying so. - One SafeTx has one gas limit; forge warns when the batch is above the block gas limit.
Suggested split, each a small PR:
- (a) move the Safe client from
crates/cast/src/cmd/safe/to a shared crate, no behavior change; - (b)
--safefor scripts with calls only; - (c) contract creation.
Would you accept this, and is the split right? If you would rather keep scripts out of it, a smaller step would be cast safe propose reading a broadcast file, so a script's dry run can be proposed in one command.
I'd like to work on this, following the split above: first move the Safe client from cast into a shared crate, then --safe for call-only scripts, then contract creation. Before starting, is this something you'd accept now, given #1232 was closed as out of scope?
This makes sense to revisit now that cast safe is in. Reusing that code for a call-only forge script --safe seems like a reasonable next step.
@0xKarl98 what do you think about this approach and the proposed split?