Skip to content

feat(cast): add --network flag to cast tx for network-specific raw encoding#13745

Merged
zerosnacks merged 2 commits intofoundry-rs:masterfrom
mablr:feature/cast_tx_raw_network_selection
Mar 16, 2026
Merged

feat(cast): add --network flag to cast tx for network-specific raw encoding#13745
zerosnacks merged 2 commits intofoundry-rs:masterfrom
mablr:feature/cast_tx_raw_network_selection

Conversation

@mablr
Copy link
Contributor

@mablr mablr commented Mar 13, 2026

Motivation

Replace the FoundryNetwork-based transaction_raw workaround with proper network selection via a new --network / -n CLI flag. This moves raw tx encoding back into Cast::transaction dispatching to the correct provider (Ethereum, Optimism, or Tempo) based on the flag.

Solution

  • Add NetworkVariant enum (Ethereum/Optimism/Tempo) in foundry-cli opts
  • use it w/ --network through CastSubcommand::Tx and provider construction
  • Add test for Tempo raw tx encoding (tx_raw_tempo)

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

…oding

Replace the `FoundryNetwork`-based `transaction_raw` workaround with proper network selection via a new `--network` / `-n` CLI flag. This moves raw tx encoding back into `Cast::transaction` dispatching to the correct
provider (Ethereum, Optimism, or Tempo) based on the flag.

- Add `NetworkVariant` enum (Ethereum/Optimism/Tempo) in foundry-cli opts
- use it w/ `--network` through CastSubcommand::Tx and provider construction
- Add test for Tempo raw tx encoding (`tx_raw_tempo`)
zerosnacks
zerosnacks previously approved these changes Mar 13, 2026
Copy link
Member

@zerosnacks zerosnacks left a comment

Choose a reason for hiding this comment

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

Nice, lgtm - pending @onbjerg's / @0xrusowsky

Comment on lines +1 to +11
/// Network selection, defaulting to Ethereum
#[derive(Clone, Debug, Default, clap::ValueEnum)]
pub enum NetworkVariant {
/// Ethereum (default)
#[default]
Ethereum,
/// Optimism / OP-stack
Optimism,
/// Tempo
Tempo,
}
Copy link
Member

@zerosnacks zerosnacks Mar 13, 2026

Choose a reason for hiding this comment

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

Makes sense, would like to get @onbjerg's input & OK on this as we had a prior conversation about this when working on tempo-foundry; what is preferable is if we somehow have a central location where this is maintained; I don't have an issue with the current proposal.

Context:

#[derive(Clone, Debug, Default, Parser, Copy, Serialize, Deserialize, PartialEq)]
pub struct NetworkConfigs {
/// Enable Optimism network features.
#[arg(help_heading = "Networks", long, conflicts_with = "celo")]
// Skipped from configs (forge) as there is no feature to be added yet.
#[serde(skip)]
optimism: bool,
/// Enable Celo network features.
#[arg(help_heading = "Networks", long, conflicts_with = "optimism")]
#[serde(default)]
celo: bool,
/// Whether to bypass prevrandao.
#[arg(skip)]
#[serde(default)]
bypass_prevrandao: bool,
}

Copy link
Contributor

@0xrusowsky 0xrusowsky left a comment

Choose a reason for hiding this comment

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

personally i like it.
let's wait for @onbjerg to have a look before merging though

Copy link
Member

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

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

for cast this makes sense, however maybe it's worth thinking about:

  1. can we autodetect the network in some cases? how would we do this? (e.g. a preliminary call to get chain id with eth transport -> use concrete provider)
  2. for forge, it would probably make sense to have this in config

wdyt?

@zerosnacks
Copy link
Member

for cast this makes sense, however maybe it's worth thinking about:

  1. can we autodetect the network in some cases? how would we do this? (e.g. a preliminary call to get chain id with eth transport -> use concrete provider)
  2. for forge, it would probably make sense to have this in config

wdyt?

Agreed; let's take this into consideration for the next steps @mablr and possibly do this as a follow-up

@zerosnacks zerosnacks merged commit 9896ecd into foundry-rs:master Mar 16, 2026
16 checks passed
@github-project-automation github-project-automation bot moved this to Done in Foundry Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants