Skip to content

Commit 8937c09

Browse files
authored
fix(anvil): --chain-id takes precendence over genesis (#10223)
1 parent a7479bc commit 8937c09

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

crates/anvil/src/cmd.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ impl NodeArgs {
223223
None => None,
224224
};
225225

226+
// --chain-id takes precedence over the genesis config
227+
// if both are missing, use the default chain id
228+
// <https://github.com/foundry-rs/foundry/issues/10059>
229+
let chain_id = self
230+
.evm
231+
.chain_id
232+
.map_or(self.init.as_ref().map_or(CHAIN_ID, |g| g.config.chain_id), |c| c.into());
226233
Ok(NodeConfig::default()
227234
.with_gas_limit(self.evm.gas_limit)
228235
.disable_block_gas_limit(self.evm.disable_block_gas_limit)
@@ -254,7 +261,7 @@ impl NodeArgs {
254261
.with_host(self.host)
255262
.set_silent(shell::is_quiet())
256263
.set_config_out(self.config_out)
257-
.with_chain_id(self.evm.chain_id)
264+
.with_chain_id(Some(chain_id))
258265
.with_transaction_order(self.order)
259266
.with_genesis(self.init)
260267
.with_steps_tracing(self.evm.steps_tracing)
@@ -278,7 +285,7 @@ impl NodeArgs {
278285
fn account_generator(&self) -> AccountGenerator {
279286
let mut gen = AccountGenerator::new(self.accounts as usize)
280287
.phrase(DEFAULT_MNEMONIC)
281-
.chain_id(self.evm.chain_id.unwrap_or_else(|| CHAIN_ID.into()));
288+
.chain_id(self.evm.chain_id.unwrap_or(CHAIN_ID.into()));
282289
if let Some(ref mnemonic) = self.mnemonic {
283290
gen = gen.phrase(mnemonic);
284291
} else if let Some(count) = self.mnemonic_random {

0 commit comments

Comments
 (0)