diff --git a/crates/cast/tests/cli/main.rs b/crates/cast/tests/cli/main.rs index cd833f7c3ed9..fe9309877b6a 100644 --- a/crates/cast/tests/cli/main.rs +++ b/crates/cast/tests/cli/main.rs @@ -1955,3 +1955,22 @@ Transaction successfully executed. "#]]); }); + +// https://github.com/foundry-rs/foundry/issues/9476 +forgetest_async!(cast_call_custom_chain_id, |_prj, cmd| { + let chain_id = 55555u64; + let (_api, handle) = anvil::spawn(NodeConfig::test().with_chain_id(Some(chain_id))).await; + + let http_endpoint = handle.http_endpoint(); + + cmd.cast_fuse() + .args([ + "call", + "5FbDB2315678afecb367f032d93F642f64180aa3", + "--rpc-url", + &http_endpoint, + "--chain", + &chain_id.to_string(), + ]) + .assert_success(); +}); diff --git a/crates/cli/src/opts/ethereum.rs b/crates/cli/src/opts/ethereum.rs index 4b15b8551940..8d2601be1638 100644 --- a/crates/cli/src/opts/ethereum.rs +++ b/crates/cli/src/opts/ethereum.rs @@ -1,4 +1,5 @@ use crate::opts::ChainValueParser; +use alloy_chains::ChainKind; use clap::Parser; use eyre::Result; use foundry_config::{ @@ -154,7 +155,11 @@ impl EtherscanOpts { dict.insert("etherscan_api_key".into(), key.into()); } if let Some(chain) = self.chain { - dict.insert("chain_id".into(), chain.to_string().into()); + if let ChainKind::Id(id) = chain.kind() { + dict.insert("chain_id".into(), (*id).into()); + } else { + dict.insert("chain_id".into(), chain.to_string().into()); + } } dict }