Skip to content

Add anvil fork mode to cartesi run#421

Open
tuler wants to merge 1 commit intoprerelease/v2-alphafrom
feature/anvil-fork
Open

Add anvil fork mode to cartesi run#421
tuler wants to merge 1 commit intoprerelease/v2-alphafrom
feature/anvil-fork

Conversation

@tuler
Copy link
Member

@tuler tuler commented Feb 11, 2026

Summary

  • Add --fork flag to cartesi run to fork from a live chain instead of using pre-baked devnet state
  • Add --fork-url <url> option to specify a custom RPC endpoint (implies --fork, defaults to https://ethereum.reth.rs/rpc)
  • Add --fork-block-number <number> option to pin the fork to a specific block

In fork mode, Anvil runs directly with --fork-url and --chain-id 31337 instead of the devnet wrapper that loads anvil_state.json. All other services (node, explorer, bundler, paymaster) continue working unchanged since the chain ID remains 31337.

Test plan

  • cartesi run --dry-run — verify normal devnet mode is unchanged (no regression)
  • cartesi run --fork --dry-run — verify anvil command uses fork with default URL
  • cartesi run --fork-url https://custom-rpc.example.com --dry-run — verify fork with custom URL (implies --fork)
  • cartesi run --fork --fork-block-number 12345 --dry-run — verify fork at specific block number
  • cartesi run --fork — verify full environment starts and is healthy against a forked chain

🤖 Generated with Claude Code

@changeset-bot
Copy link

changeset-bot bot commented Feb 11, 2026

🦋 Changeset detected

Latest commit: d559b36

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cartesi/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tuler tuler changed the title feat(cli): add anvil fork mode to cartesi run Add anvil fork mode to cartesi run Feb 11, 2026
@tuler tuler changed the base branch from main to prerelease/v2-alpha February 11, 2026 20:22
@tuler tuler force-pushed the feature/anvil-fork branch from 39e4df4 to 2c2d626 Compare February 11, 2026 20:23
@github-actions
Copy link
Contributor

github-actions bot commented Feb 11, 2026

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 92.96% (🎯 0%) 726 / 781
🔵 Statements 92.96% 726 / 781
🔵 Functions 92.54% 62 / 67
🔵 Branches 0% 0 / 0
📁 File Coverage (11 files)
File Lines Statements Functions Branches Uncovered Lines
apps/cli/src/builder/directory.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/builder/docker.ts 🟢 88.68% 🟢 88.68% 🟡 75% 🔴 0% 83-85, 139-147
apps/cli/src/builder/empty.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/builder/none.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/builder/tar.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/config.ts 🟢 92.63% 🟢 92.63% 🟢 94.12% 🔴 0% 65-66, 217, 226, 235, 255, ...
apps/cli/src/exec/cartesi-machine.ts 🟡 75% 🟡 75% 🟡 66.67% 🔴 0% 10-12, 28-30
apps/cli/src/exec/genext2fs.ts 🟢 96.92% 🟢 96.92% 🟢 100% 🔴 0% 87-88
apps/cli/src/exec/index.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/exec/mksquashfs.ts 🟢 91.23% 🟢 91.23% 🟢 100% 🔴 0% 68-72
apps/cli/src/exec/util.ts 🟢 94.44% 🟢 94.44% 🟢 100% 🔴 0% 47-48

@tuler tuler requested a review from endersonmaia February 11, 2026 21:35
@tuler tuler force-pushed the feature/anvil-fork branch from a7da1d3 to 71d8c01 Compare February 12, 2026 05:08
@socket-security
Copy link

socket-security bot commented Feb 12, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​sunodo/​wagmi-plugin-hardhat-deploy@​0.4.0701008981100
Addedtmp@​0.2.510010010082100
Addedsmol-toml@​1.6.010010010087100
Addedyaml@​2.8.29910010089100
Updated@​cartesi/​devnet@​2.0.0-alpha.9 ⏵ 2.0.0-alpha.10100 +22100100 +28100 +9100

View full report

@tuler tuler force-pushed the feature/anvil-fork branch from 71d8c01 to 4982e0f Compare February 12, 2026 05:31
@tuler
Copy link
Member Author

tuler commented Feb 12, 2026

Depending on the chosen fork-url the deployed contracts can have different addresses.
ps: in fact only 1 contract from Cartesi framework currently have this "problem": DaveAppFactory.

So the CLI needs to use the correct address during application deployment, and also report the correct address in the address-book command.

So it should know not only the addresses on local deployment, but also the addresses on all supported live networks, which can potentially be forked.

So I had to modify the devnet package to also package the deployments from all networks, which is maintained at cannon registry.

So I changed to devnet packaging to call cannon inspect, and export the addresses from all networks. And changed the artifact format to follow the format supported by the wagmi-hardhat-plugin, because then it would be much easier to use.

When merged the devnet package will need to be released first, then SDK, then CLI.

@tuler tuler changed the base branch from prerelease/v2-alpha to feature/devnet-live-networks February 12, 2026 16:40
@tuler tuler changed the base branch from feature/devnet-live-networks to feature/sdk-bump-devnet February 12, 2026 16:44
@tuler tuler force-pushed the feature/sdk-bump-devnet branch from 70df749 to feb831d Compare February 12, 2026 18:32
@tuler tuler force-pushed the feature/anvil-fork branch from f39a101 to e580d99 Compare February 12, 2026 18:33
Base automatically changed from feature/sdk-bump-devnet to prerelease/v2-alpha February 16, 2026 16:57
@tuler tuler force-pushed the feature/anvil-fork branch from e580d99 to 8224b62 Compare February 16, 2026 16:59
Allow forking from a live chain instead of using pre-baked devnet state.
Adds --fork, --fork-url, and --fork-block-number options.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tuler tuler force-pushed the feature/anvil-fork branch from 8224b62 to d559b36 Compare February 16, 2026 17:13
@tuler tuler marked this pull request as ready for review February 16, 2026 18:00
@tuler tuler requested a review from brunomenezes February 16, 2026 18:00
@brunomenezes
Copy link
Contributor

...
So I changed to devnet packaging to call cannon inspect, and export the addresses from all networks. And changed the artifact format to follow the format supported by the wagmi-hardhat-plugin, because then it would be much easier to use.

When merged the devnet package will need to be released first, then SDK, then CLI.

So, are these devnet changes in some other PR? Also, I tried building the CLI from this branch, but it fails on the devnet package. Building it in isolation, here are the logs I received. Is there a specific version that is expected? Currently, my system is using 1.5.0-stable.

@cartesi/devnet:build:
@cartesi/devnet:build: IPFS Availability Score(# of nodes):  Run IPFS Locally to get this score
@cartesi/devnet:build:
✖ Failed to parse anvil version. Is anvil installed?
@cartesi/devnet:build: ✔ Download dependencies
@cartesi/devnet:build: ✔ Anvil started (PID: 98596)
@cartesi/devnet:build: ✔ Contracts deployed
@cartesi/devnet:build: ✔ Local deployments written to deployments/anvil.json
@cartesi/devnet:build: ✔ Export cannon packages
@cartesi/devnet:build: ✔ Anvil stopped -> anvil_state.json
@cartesi/devnet:build: error: script "build:dump" exited with code 1
@cartesi/devnet:build: ERROR: "build:dump" exited with 1.
@cartesi/devnet:build: error: script "build" exited with code 1
@cartesi/devnet:build: ERROR: command finished with error: command (/Users/--x--/cartesi/public/cli/packages/devnet) /opt/homebrew/bin/bun run build exited (1)
@cartesi/devnet#build: command (/Users/--x--/cartesi/public/cli/packages/devnet) /opt/homebrew/bin/bun run build exited (1)

 Tasks:    0 successful, 1 total                     └───────────────────┘
Cached:    0 cached, 1 total
  Time:    7.866s
Failed:    @cartesi/devnet#build

Copy link
Contributor

@brunomenezes brunomenezes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the dry-runs suggested and also create/build/run an dapp. No hiccups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants