Skip to content

Commit

Permalink
feat(cli): add a RPC batch option to cli (#2322)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <[email protected]>
  • Loading branch information
0x-shanks and holic authored Mar 5, 2024
1 parent 90d0d79 commit 645736d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/angry-buses-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/cli": minor
---

Added an `--rpcBatch` option to `mud deploy` command to batch RPC calls for rate limited RPCs.
1 change: 1 addition & 0 deletions docs/pages/cli/deploy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ These are the command line options you can specify on `mud deploy`:
| `--saveDeployment | Save the deployment info to a file | boolean | `true` |
| `--profile` | The foundry profile to use | string | `local` |
| `--rpc`<sup>1</sup> | The RPC URL to use | string | RPC url from `foundry.toml` |
| `--rpcBatch` | Enable batch processing of RPC requests | boolean | `false` |
| `--worldAddress` | Deploy to an existing World at the given address | string | Empty, deploy new `World` |
| `--srcDir` | Source directory | string | Foundry `src` directory |
| `--skipBuild` | Skip rebuilding the contracts before deploying | boolean | `false` |
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/dev-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const commandModule: CommandModule<typeof devOptions, InferredOptionTypes<typeof
...opts,
configPath,
rpc,
rpcBatch: false,
skipBuild: false,
printConfig: false,
profile: undefined,
Expand Down
13 changes: 12 additions & 1 deletion packages/cli/src/runDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const deployOptions = {
profile: { type: "string", desc: "The foundry profile to use" },
saveDeployment: { type: "boolean", desc: "Save the deployment info to a file", default: true },
rpc: { type: "string", desc: "The RPC URL to use. Defaults to the RPC url from the local foundry.toml" },
rpcBatch: {
type: "boolean",
desc: "Enable batch processing of RPC requests in viem client (defaults to batch size of 100 and wait of 1s)",
},
deployerAddress: {
type: "string",
desc: "Deploy using an existing deterministic deployer (https://github.com/Arachnid/deterministic-deployment-proxy)",
Expand Down Expand Up @@ -85,7 +89,14 @@ in your contracts directory to use the default anvil private key.`,
const resolvedConfig = resolveConfig({ config, forgeSourceDir: srcDir, forgeOutDir: outDir });

const client = createWalletClient({
transport: http(rpc),
transport: http(rpc, {
batch: opts.rpcBatch
? {
batchSize: 100,
wait: 1000,
}
: undefined,
}),
account: privateKeyToAccount(privateKey),
});
console.log("Deploying from", client.account.address);
Expand Down

0 comments on commit 645736d

Please sign in to comment.