Lines 1-38javascript
2// forge_broadcast.js — Run `forge script --broadcast` fast and reliably on anvil.
4// anvil's automine mines each deploy transaction essentially instantly, which is what we want for
5// speed. But a batched broadcast (forge's default sends many txs at once) can race the auto-miner:
6// it mines a block on the first ready tx and may leave txs that arrived just after the trigger
7// sitting in the pool, so forge waits forever for their receipts. We avoid the race without touching
8// anvil's mining mode by broadcasting one tx at a time (`--batch-size 1`) only when anvil has
9// automine ON: with a single tx in flight there is nothing for the auto-miner to strand.
11// When anvil is in interval (or no) mining mode the race does not exist — the miner drains the whole
12// pool on each block — and serializing to one tx per block would stall the deploy for a full block
13// interval per transaction, blowing past the broadcast timeout. There (and on real chains) we keep a
14// larger batch size. A hard timeout guards against a broadcast hanging indefinitely.
16// Usage: ./scripts/forge_broadcast.js <forge script args...>
17// (without --broadcast or --batch-size — added automatically)
19import { spawn } from "node:child_process";
20import { writeSync } from "node:fs";
HighChild Process
Package source references child process execution.
l1-contracts/scripts/forge_broadcast.jsView on unpkg · L18 22const log = (msg) => process.stderr.write(`[forge_broadcast] ${msg}\n`);
24async function rpc(url, method, params = []) {
25 const res = await fetch(url, {
26 method: "POST",
HighCommand Output Exfiltration
Source combines command execution, command-output handling, and outbound requests; review data flow before blocking.
l1-contracts/scripts/forge_broadcast.jsView on unpkg · L18 27 headers: { "Content-Type": "application/json" },
28 body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }),
29 signal: AbortSignal.timeout(10_000),
31 const json = await res.json();
32 if (json.error) throw new Error(json.error.message);
36function extractArg(args, flag) {
37 const i = args.indexOf(flag);
38 return i >= 0 && i < args.length - 1 ? args[i + 1] : undefined;