@@ -223,6 +223,13 @@ impl NodeArgs {
223
223
None => None ,
224
224
} ;
225
225
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 ( ) ) ;
226
233
Ok ( NodeConfig :: default ( )
227
234
. with_gas_limit ( self . evm . gas_limit )
228
235
. disable_block_gas_limit ( self . evm . disable_block_gas_limit )
@@ -254,7 +261,7 @@ impl NodeArgs {
254
261
. with_host ( self . host )
255
262
. set_silent ( shell:: is_quiet ( ) )
256
263
. set_config_out ( self . config_out )
257
- . with_chain_id ( self . evm . chain_id )
264
+ . with_chain_id ( Some ( chain_id) )
258
265
. with_transaction_order ( self . order )
259
266
. with_genesis ( self . init )
260
267
. with_steps_tracing ( self . evm . steps_tracing )
@@ -278,7 +285,7 @@ impl NodeArgs {
278
285
fn account_generator ( & self ) -> AccountGenerator {
279
286
let mut gen = AccountGenerator :: new ( self . accounts as usize )
280
287
. 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 ( ) ) ) ;
282
289
if let Some ( ref mnemonic) = self . mnemonic {
283
290
gen = gen. phrase ( mnemonic) ;
284
291
} else if let Some ( count) = self . mnemonic_random {
0 commit comments