alloy_chains/
named.rs

1use alloy_primitives::{address, Address};
2use core::{cmp::Ordering, fmt, time::Duration};
3use num_enum::TryFromPrimitiveError;
4
5#[allow(unused_imports)]
6use alloc::string::String;
7// When adding a new chain:
8//   1. add new variant to the NamedChain enum;
9//   2. add extra information in the last `impl` block (explorer URLs, block time) when applicable;
10//   3. (optional) add aliases:
11//     - Strum (in kebab-case): `#[strum(to_string = "<main>", serialize = "<aliasX>", ...)]`
12//      `to_string = "<main>"` must be present and will be used in `Display`, `Serialize`
13//      and `FromStr`, while `serialize = "<aliasX>"` will be appended to `FromStr`.
14//      More info: <https://docs.rs/strum/latest/strum/additional_attributes/index.html#attributes-on-variants>
15//     - Serde (in snake_case): `#[cfg_attr(feature = "serde", serde(alias = "<aliasX>", ...))]`
16//      Aliases are appended to the `Deserialize` implementation.
17//      More info: <https://serde.rs/variant-attrs.html>
18//     - Add a test at the bottom of the file
19//   4. run `cargo test --all-features` to update the JSON bindings and schema.
20//   5. run `cargo fmt --all` to properly format the code.
21
22// We don't derive Serialize because it is manually implemented using AsRef<str> and it would break
23// a lot of things since Serialize is `kebab-case` vs Deserialize `snake_case`. This means that the
24// NamedChain type is not "round-trippable", because the Serialize and Deserialize implementations
25// do not use the same case style.
26
27/// An Ethereum EIP-155 chain.
28#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
29#[derive(strum::IntoStaticStr)] // Into<&'static str>, AsRef<str>, fmt::Display and serde::Serialize
30#[derive(strum::VariantNames)] // NamedChain::VARIANTS
31#[derive(strum::VariantArray)] // NamedChain::VARIANTS
32#[derive(strum::EnumString)] // FromStr, TryFrom<&str>
33#[derive(strum::EnumIter)] // NamedChain::iter
34#[derive(strum::EnumCount)] // NamedChain::COUNT
35#[derive(num_enum::TryFromPrimitive)] // TryFrom<u64>
36#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
37#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
38#[strum(serialize_all = "kebab-case")]
39#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
40#[repr(u64)]
41#[allow(missing_docs)]
42#[non_exhaustive]
43pub enum NamedChain {
44    #[strum(to_string = "mainnet", serialize = "ethlive")]
45    #[cfg_attr(feature = "serde", serde(alias = "ethlive"))]
46    Mainnet = 1,
47    Morden = 2,
48    Ropsten = 3,
49    Rinkeby = 4,
50    Goerli = 5,
51    Kovan = 42,
52    Holesky = 17000,
53    Hoodi = 560048,
54    Sepolia = 11155111,
55
56    #[cfg_attr(feature = "serde", serde(alias = "odyssey"))]
57    Odyssey = 911867,
58
59    Optimism = 10,
60    #[cfg_attr(feature = "serde", serde(alias = "optimism-kovan"))]
61    OptimismKovan = 69,
62    #[cfg_attr(feature = "serde", serde(alias = "optimism-goerli"))]
63    OptimismGoerli = 420,
64    #[cfg_attr(feature = "serde", serde(alias = "optimism-sepolia"))]
65    OptimismSepolia = 11155420,
66
67    #[strum(to_string = "bob")]
68    #[cfg_attr(feature = "serde", serde(alias = "bob"))]
69    Bob = 60808,
70    #[strum(to_string = "bob-sepolia")]
71    #[cfg_attr(feature = "serde", serde(alias = "bob-sepolia"))]
72    BobSepolia = 808813,
73
74    #[cfg_attr(feature = "serde", serde(alias = "arbitrum_one", alias = "arbitrum-one"))]
75    Arbitrum = 42161,
76    ArbitrumTestnet = 421611,
77    #[cfg_attr(feature = "serde", serde(alias = "arbitrum-goerli"))]
78    ArbitrumGoerli = 421613,
79    #[cfg_attr(feature = "serde", serde(alias = "arbitrum-sepolia"))]
80    ArbitrumSepolia = 421614,
81    #[cfg_attr(feature = "serde", serde(alias = "arbitrum-nova"))]
82    ArbitrumNova = 42170,
83
84    Cronos = 25,
85    CronosTestnet = 338,
86
87    Rsk = 30,
88    RskTestnet = 31,
89
90    #[strum(to_string = "telos")]
91    #[cfg_attr(feature = "serde", serde(alias = "telos", alias = "telos_evm"))]
92    TelosEvm = 40,
93    #[strum(to_string = "telos-testnet")]
94    #[cfg_attr(
95        feature = "serde",
96        serde(alias = "telos_testnet", alias = "telos-evm-testnet", alias = "telos_evm_testnet")
97    )]
98    TelosEvmTestnet = 41,
99
100    #[strum(to_string = "crab")]
101    #[cfg_attr(feature = "serde", serde(alias = "crab"))]
102    Crab = 44,
103    #[strum(to_string = "darwinia")]
104    #[cfg_attr(feature = "serde", serde(alias = "darwinia"))]
105    Darwinia = 46,
106    #[strum(to_string = "koi")]
107    #[cfg_attr(feature = "serde", serde(alias = "koi"))]
108    Koi = 701,
109
110    /// Note the correct name for BSC should be `BNB Smart Chain` due to the rebranding: <https://www.bnbchain.org/en/blog/bsc-is-now-bnb-chain-the-infrastructure-for-the-metafi-universe>
111    /// We keep `Binance Smart Chain` for backward compatibility, and the enum could be renamed in
112    /// the future release.
113    #[strum(to_string = "bsc", serialize = "binance-smart-chain", serialize = "bnb-smart-chain")]
114    #[cfg_attr(
115        feature = "serde",
116        serde(alias = "bsc", alias = "bnb-smart-chain", alias = "binance-smart-chain")
117    )]
118    BinanceSmartChain = 56,
119    #[strum(
120        to_string = "bsc-testnet",
121        serialize = "binance-smart-chain-testnet",
122        serialize = "bnb-smart-chain-testnet"
123    )]
124    #[cfg_attr(
125        feature = "serde",
126        serde(
127            alias = "bsc_testnet",
128            alias = "bsc-testnet",
129            alias = "bnb-smart-chain-testnet",
130            alias = "binance-smart-chain-testnet"
131        )
132    )]
133    BinanceSmartChainTestnet = 97,
134
135    Poa = 99,
136    Sokol = 77,
137
138    Scroll = 534352,
139    #[cfg_attr(
140        feature = "serde",
141        serde(alias = "scroll_sepolia_testnet", alias = "scroll-sepolia")
142    )]
143    ScrollSepolia = 534351,
144
145    Metis = 1088,
146
147    #[cfg_attr(feature = "serde", serde(alias = "conflux-espace-testnet"))]
148    CfxTestnet = 71,
149    #[cfg_attr(feature = "serde", serde(alias = "conflux-espace"))]
150    Cfx = 1030,
151
152    #[strum(to_string = "xdai", serialize = "gnosis", serialize = "gnosis-chain")]
153    #[cfg_attr(feature = "serde", serde(alias = "xdai", alias = "gnosis", alias = "gnosis-chain"))]
154    Gnosis = 100,
155
156    Polygon = 137,
157    #[strum(to_string = "mumbai", serialize = "polygon-mumbai")]
158    #[cfg_attr(feature = "serde", serde(alias = "mumbai", alias = "polygon-mumbai"))]
159    PolygonMumbai = 80001,
160    #[strum(to_string = "amoy", serialize = "polygon-amoy")]
161    #[cfg_attr(feature = "serde", serde(alias = "amoy", alias = "polygon-amoy"))]
162    PolygonAmoy = 80002,
163    #[strum(serialize = "polygon-zkevm", serialize = "zkevm")]
164    #[cfg_attr(
165        feature = "serde",
166        serde(alias = "zkevm", alias = "polygon_zkevm", alias = "polygon-zkevm")
167    )]
168    PolygonZkEvm = 1101,
169    #[strum(serialize = "polygon-zkevm-testnet", serialize = "zkevm-testnet")]
170    #[cfg_attr(
171        feature = "serde",
172        serde(
173            alias = "zkevm-testnet",
174            alias = "polygon_zkevm_testnet",
175            alias = "polygon-zkevm-testnet"
176        )
177    )]
178    PolygonZkEvmTestnet = 1442,
179
180    Fantom = 250,
181    FantomTestnet = 4002,
182
183    Moonbeam = 1284,
184    MoonbeamDev = 1281,
185
186    Moonriver = 1285,
187
188    Moonbase = 1287,
189
190    Dev = 1337,
191    #[strum(to_string = "anvil-hardhat", serialize = "anvil", serialize = "hardhat")]
192    #[cfg_attr(
193        feature = "serde",
194        serde(alias = "anvil", alias = "hardhat", alias = "anvil-hardhat")
195    )]
196    AnvilHardhat = 31337,
197
198    #[strum(to_string = "gravity-alpha-mainnet")]
199    #[cfg_attr(feature = "serde", serde(alias = "gravity-alpha-mainnet"))]
200    GravityAlphaMainnet = 1625,
201    #[strum(to_string = "gravity-alpha-testnet-sepolia")]
202    #[cfg_attr(feature = "serde", serde(alias = "gravity-alpha-testnet-sepolia"))]
203    GravityAlphaTestnetSepolia = 13505,
204
205    Evmos = 9001,
206    EvmosTestnet = 9000,
207
208    Chiado = 10200,
209
210    Oasis = 26863,
211
212    Emerald = 42262,
213    EmeraldTestnet = 42261,
214
215    FilecoinMainnet = 314,
216    FilecoinCalibrationTestnet = 314159,
217
218    Avalanche = 43114,
219    #[strum(to_string = "fuji", serialize = "avalanche-fuji")]
220    #[cfg_attr(feature = "serde", serde(alias = "fuji"))]
221    AvalancheFuji = 43113,
222
223    Celo = 42220,
224    CeloAlfajores = 44787,
225    CeloBaklava = 62320,
226
227    Aurora = 1313161554,
228    AuroraTestnet = 1313161555,
229
230    Canto = 7700,
231    CantoTestnet = 740,
232
233    Boba = 288,
234
235    Base = 8453,
236    #[cfg_attr(feature = "serde", serde(alias = "base-goerli"))]
237    BaseGoerli = 84531,
238    #[cfg_attr(feature = "serde", serde(alias = "base-sepolia"))]
239    BaseSepolia = 84532,
240    #[cfg_attr(feature = "serde", serde(alias = "syndr"))]
241    Syndr = 404,
242    #[cfg_attr(feature = "serde", serde(alias = "syndr-sepolia"))]
243    SyndrSepolia = 444444,
244
245    Shimmer = 148,
246
247    Ink = 57073,
248    #[cfg_attr(feature = "serde", serde(alias = "ink_sepolia_testnet", alias = "ink-sepolia"))]
249    InkSepolia = 763373,
250
251    #[strum(to_string = "fraxtal")]
252    #[cfg_attr(feature = "serde", serde(alias = "fraxtal"))]
253    Fraxtal = 252,
254    #[strum(to_string = "fraxtal-testnet")]
255    #[cfg_attr(feature = "serde", serde(alias = "fraxtal-testnet"))]
256    FraxtalTestnet = 2522,
257
258    Blast = 81457,
259    #[cfg_attr(feature = "serde", serde(alias = "blast-sepolia"))]
260    BlastSepolia = 168587773,
261
262    Linea = 59144,
263    #[cfg_attr(feature = "serde", serde(alias = "linea-goerli"))]
264    LineaGoerli = 59140,
265    #[cfg_attr(feature = "serde", serde(alias = "linea-sepolia"))]
266    LineaSepolia = 59141,
267
268    #[strum(to_string = "zksync")]
269    #[cfg_attr(feature = "serde", serde(alias = "zksync"))]
270    ZkSync = 324,
271    #[strum(to_string = "zksync-testnet")]
272    #[cfg_attr(feature = "serde", serde(alias = "zksync_testnet", alias = "zksync-testnet"))]
273    ZkSyncTestnet = 300,
274
275    #[strum(to_string = "mantle")]
276    #[cfg_attr(feature = "serde", serde(alias = "mantle"))]
277    Mantle = 5000,
278    #[strum(to_string = "mantle-testnet")]
279    #[cfg_attr(feature = "serde", serde(alias = "mantle-testnet"))]
280    MantleTestnet = 5001,
281    #[strum(to_string = "mantle-sepolia")]
282    #[cfg_attr(feature = "serde", serde(alias = "mantle-sepolia"))]
283    MantleSepolia = 5003,
284
285    #[strum(to_string = "xai")]
286    #[cfg_attr(feature = "serde", serde(alias = "xai"))]
287    Xai = 660279,
288    #[strum(to_string = "xai-sepolia")]
289    #[cfg_attr(feature = "serde", serde(alias = "xai-sepolia"))]
290    XaiSepolia = 37714555429,
291
292    #[strum(to_string = "happychain-testnet")]
293    #[cfg_attr(feature = "serde", serde(alias = "happychain-testnet"))]
294    HappychainTestnet = 216,
295
296    Viction = 88,
297
298    Zora = 7777777,
299    #[cfg_attr(feature = "serde", serde(alias = "zora-sepolia"))]
300    ZoraSepolia = 999999999,
301
302    Pgn = 424,
303    #[cfg_attr(feature = "serde", serde(alias = "pgn-sepolia"))]
304    PgnSepolia = 58008,
305
306    Mode = 34443,
307    #[cfg_attr(feature = "serde", serde(alias = "mode-sepolia"))]
308    ModeSepolia = 919,
309
310    Elastos = 20,
311
312    #[cfg_attr(
313        feature = "serde",
314        serde(alias = "kakarot-sepolia", alias = "kakarot-starknet-sepolia")
315    )]
316    KakarotSepolia = 920637907288165,
317
318    #[cfg_attr(feature = "serde", serde(alias = "etherlink"))]
319    Etherlink = 42793,
320
321    #[cfg_attr(feature = "serde", serde(alias = "etherlink-testnet"))]
322    EtherlinkTestnet = 128123,
323
324    Degen = 666666666,
325
326    #[strum(to_string = "opbnb-mainnet")]
327    #[cfg_attr(
328        feature = "serde",
329        serde(rename = "opbnb_mainnet", alias = "opbnb-mainnet", alias = "op-bnb-mainnet")
330    )]
331    OpBNBMainnet = 204,
332    #[strum(to_string = "opbnb-testnet")]
333    #[cfg_attr(
334        feature = "serde",
335        serde(rename = "opbnb_testnet", alias = "opbnb-testnet", alias = "op-bnb-testnet")
336    )]
337    OpBNBTestnet = 5611,
338
339    Ronin = 2020,
340
341    #[cfg_attr(feature = "serde", serde(alias = "ronin-testnet"))]
342    RoninTestnet = 2021,
343
344    Taiko = 167000,
345    #[cfg_attr(feature = "serde", serde(alias = "taiko-hekla"))]
346    TaikoHekla = 167009,
347
348    #[strum(to_string = "autonomys-nova-testnet")]
349    #[cfg_attr(
350        feature = "serde",
351        serde(rename = "autonomys_nova_testnet", alias = "autonomys-nova-testnet")
352    )]
353    AutonomysNovaTestnet = 490000,
354
355    Flare = 14,
356    #[cfg_attr(feature = "serde", serde(alias = "flare-coston2"))]
357    FlareCoston2 = 114,
358
359    #[strum(to_string = "acala")]
360    #[cfg_attr(feature = "serde", serde(alias = "acala"))]
361    Acala = 787,
362    #[strum(to_string = "acala-mandala-testnet")]
363    #[cfg_attr(feature = "serde", serde(alias = "acala-mandala-testnet"))]
364    AcalaMandalaTestnet = 595,
365    #[strum(to_string = "acala-testnet")]
366    #[cfg_attr(feature = "serde", serde(alias = "acala-testnet"))]
367    AcalaTestnet = 597,
368
369    #[strum(to_string = "karura")]
370    #[cfg_attr(feature = "serde", serde(alias = "karura"))]
371    Karura = 686,
372    #[strum(to_string = "karura-testnet")]
373    #[cfg_attr(feature = "serde", serde(alias = "karura-testnet"))]
374    KaruraTestnet = 596,
375    #[strum(to_string = "pulsechain")]
376    #[cfg_attr(feature = "serde", serde(alias = "pulsechain"))]
377    Pulsechain = 369,
378    #[strum(to_string = "pulsechain-testnet")]
379    #[cfg_attr(feature = "serde", serde(alias = "pulsechain-testnet"))]
380    PulsechainTestnet = 943,
381
382    #[strum(to_string = "immutable")]
383    #[cfg_attr(feature = "serde", serde(alias = "immutable"))]
384    Immutable = 13371,
385    #[strum(to_string = "immutable-testnet")]
386    #[cfg_attr(feature = "serde", serde(alias = "immutable-testnet"))]
387    ImmutableTestnet = 13473,
388
389    #[strum(to_string = "soneium")]
390    #[cfg_attr(feature = "serde", serde(alias = "soneium"))]
391    Soneium = 1868,
392
393    #[strum(to_string = "soneium-minato-testnet")]
394    #[cfg_attr(feature = "serde", serde(alias = "soneium-minato-testnet"))]
395    SoneiumMinatoTestnet = 1946,
396
397    #[cfg_attr(feature = "serde", serde(alias = "worldchain"))]
398    World = 480,
399    #[strum(to_string = "world-sepolia")]
400    #[cfg_attr(feature = "serde", serde(alias = "worldchain-sepolia", alias = "world-sepolia"))]
401    WorldSepolia = 4801,
402    Iotex = 4689,
403    Core = 1116,
404    Merlin = 4200,
405    Bitlayer = 200901,
406    Vana = 1480,
407    Zeta = 7000,
408    Kaia = 8217,
409    Story = 1514,
410    Sei = 1329,
411
412    Unichain = 130,
413    #[strum(to_string = "unichain-sepolia")]
414    #[cfg_attr(feature = "serde", serde(alias = "unichain-sepolia"))]
415    UnichainSepolia = 1301,
416
417    #[strum(to_string = "apechain")]
418    #[cfg_attr(feature = "serde", serde(alias = "apechain"))]
419    ApeChain = 33139,
420    #[strum(to_string = "curtis", serialize = "apechain-testnet")]
421    #[cfg_attr(feature = "serde", serde(alias = "apechain-testnet", alias = "curtis"))]
422    Curtis = 33111,
423
424    #[strum(to_string = "sonic-blaze")]
425    #[cfg_attr(feature = "serde", serde(alias = "sonic-blaze"))]
426    SonicBlaze = 57054,
427    #[strum(to_string = "sonic-testnet")]
428    #[cfg_attr(feature = "serde", serde(alias = "sonic-testnet"))]
429    SonicTestnet = 64165,
430    #[strum(to_string = "sonic")]
431    #[cfg_attr(feature = "serde", serde(alias = "sonic"))]
432    Sonic = 146,
433
434    #[strum(to_string = "treasure")]
435    #[cfg_attr(feature = "serde", serde(alias = "treasure"))]
436    Treasure = 61166,
437
438    #[strum(to_string = "treasure-topaz", serialize = "treasure-topaz-testnet")]
439    #[cfg_attr(
440        feature = "serde",
441        serde(alias = "treasure-topaz-testnet", alias = "treasure-topaz")
442    )]
443    TreasureTopaz = 978658,
444
445    #[strum(to_string = "berachain-bepolia", serialize = "berachain-bepolia-testnet")]
446    #[cfg_attr(
447        feature = "serde",
448        serde(alias = "berachain-bepolia-testnet", alias = "berachain-bepolia")
449    )]
450    BerachainBepolia = 80069,
451
452    #[strum(to_string = "berachain-bartio", serialize = "berachain-bartio-testnet")]
453    #[cfg_attr(
454        feature = "serde",
455        serde(alias = "berachain-bartio-testnet", alias = "berachain-bartio")
456    )]
457    BerachainBartio = 80084,
458
459    #[strum(to_string = "berachain-artio", serialize = "berachain-artio-testnet")]
460    #[cfg_attr(
461        feature = "serde",
462        serde(alias = "berachain-artio-testnet", alias = "berachain-artio")
463    )]
464    BerachainArtio = 80085,
465
466    Berachain = 80094,
467
468    #[strum(to_string = "superposition-testnet")]
469    #[cfg_attr(feature = "serde", serde(alias = "superposition-testnet"))]
470    SuperpositionTestnet = 98985,
471
472    #[strum(to_string = "superposition")]
473    #[cfg_attr(feature = "serde", serde(alias = "superposition"))]
474    Superposition = 55244,
475
476    #[strum(serialize = "monad-testnet")]
477    #[cfg_attr(feature = "serde", serde(alias = "monad-testnet"))]
478    MonadTestnet = 10143,
479
480    #[strum(to_string = "hyperliquid")]
481    #[cfg_attr(feature = "serde", serde(alias = "hyperliquid"))]
482    Hyperliquid = 999,
483
484    #[strum(to_string = "abstract")]
485    #[cfg_attr(feature = "serde", serde(alias = "abstract"))]
486    Abstract = 2741,
487
488    #[strum(to_string = "abstract-testnet")]
489    #[cfg_attr(feature = "serde", serde(alias = "abstract-testnet"))]
490    AbstractTestnet = 11124,
491
492    #[strum(to_string = "corn")]
493    #[cfg_attr(feature = "serde", serde(alias = "corn"))]
494    Corn = 21000000,
495
496    #[strum(to_string = "corn-testnet")]
497    #[cfg_attr(feature = "serde", serde(alias = "corn-testnet"))]
498    CornTestnet = 21000001,
499
500    #[strum(to_string = "sophon")]
501    #[cfg_attr(feature = "serde", serde(alias = "sophon"))]
502    Sophon = 50104,
503
504    #[strum(to_string = "sophon-testnet")]
505    #[cfg_attr(feature = "serde", serde(alias = "sophon-testnet"))]
506    SophonTestnet = 531050104,
507
508    #[strum(to_string = "lens")]
509    #[cfg_attr(feature = "serde", serde(alias = "lens"))]
510    Lens = 232,
511
512    #[strum(to_string = "lens-testnet")]
513    #[cfg_attr(feature = "serde", serde(alias = "lens-testnet"))]
514    LensTestnet = 37111,
515}
516
517// This must be implemented manually so we avoid a conflict with `TryFromPrimitive` where it treats
518// the `#[default]` attribute as its own `#[num_enum(default)]`
519impl Default for NamedChain {
520    #[inline]
521    fn default() -> Self {
522        Self::Mainnet
523    }
524}
525
526macro_rules! impl_into_numeric {
527    ($($t:ty)+) => {$(
528        impl From<NamedChain> for $t {
529            #[inline]
530            fn from(chain: NamedChain) -> Self {
531                chain as $t
532            }
533        }
534    )+};
535}
536
537impl_into_numeric!(u64 i64 u128 i128);
538#[cfg(target_pointer_width = "64")]
539impl_into_numeric!(usize isize);
540
541macro_rules! impl_try_from_numeric {
542    ($($native:ty)+) => {
543        $(
544            impl TryFrom<$native> for NamedChain {
545                type Error = TryFromPrimitiveError<NamedChain>;
546
547                #[inline]
548                fn try_from(value: $native) -> Result<Self, Self::Error> {
549                    (value as u64).try_into()
550                }
551            }
552        )+
553    };
554}
555
556impl_try_from_numeric!(u8 i8 u16 i16 u32 i32 usize isize);
557
558impl fmt::Display for NamedChain {
559    #[inline]
560    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
561        self.as_str().fmt(f)
562    }
563}
564
565impl AsRef<str> for NamedChain {
566    #[inline]
567    fn as_ref(&self) -> &str {
568        self.as_str()
569    }
570}
571
572impl PartialEq<u64> for NamedChain {
573    #[inline]
574    fn eq(&self, other: &u64) -> bool {
575        (*self as u64) == *other
576    }
577}
578
579impl PartialOrd<u64> for NamedChain {
580    #[inline]
581    fn partial_cmp(&self, other: &u64) -> Option<Ordering> {
582        (*self as u64).partial_cmp(other)
583    }
584}
585
586#[cfg(feature = "serde")]
587impl serde::Serialize for NamedChain {
588    #[inline]
589    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
590        s.serialize_str(self.as_ref())
591    }
592}
593
594#[cfg(feature = "rlp")]
595impl alloy_rlp::Encodable for NamedChain {
596    #[inline]
597    fn encode(&self, out: &mut dyn alloy_rlp::BufMut) {
598        (*self as u64).encode(out)
599    }
600
601    #[inline]
602    fn length(&self) -> usize {
603        (*self as u64).length()
604    }
605}
606
607#[cfg(feature = "rlp")]
608impl alloy_rlp::Decodable for NamedChain {
609    #[inline]
610    fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
611        let n = u64::decode(buf)?;
612        Self::try_from(n).map_err(|_| alloy_rlp::Error::Overflow)
613    }
614}
615
616// NB: all utility functions *should* be explicitly exhaustive (not use `_` matcher) so we don't
617//     forget to update them when adding a new `NamedChain` variant.
618#[allow(clippy::match_like_matches_macro)]
619#[deny(unreachable_patterns, unused_variables)]
620impl NamedChain {
621    /// Returns the string representation of the chain.
622    #[inline]
623    pub fn as_str(&self) -> &'static str {
624        self.into()
625    }
626
627    /// Returns `true` if this chain is Ethereum or an Ethereum testnet.
628    pub const fn is_ethereum(&self) -> bool {
629        use NamedChain::*;
630
631        matches!(self, Mainnet | Morden | Ropsten | Rinkeby | Goerli | Kovan | Holesky | Sepolia)
632    }
633
634    /// Returns true if the chain contains Optimism configuration.
635    pub const fn is_optimism(self) -> bool {
636        use NamedChain::*;
637
638        matches!(
639            self,
640            Optimism
641                | OptimismGoerli
642                | OptimismKovan
643                | OptimismSepolia
644                | Base
645                | BaseGoerli
646                | BaseSepolia
647                | Fraxtal
648                | FraxtalTestnet
649                | Ink
650                | InkSepolia
651                | Mode
652                | ModeSepolia
653                | Pgn
654                | PgnSepolia
655                | Zora
656                | ZoraSepolia
657                | BlastSepolia
658                | OpBNBMainnet
659                | OpBNBTestnet
660                | Soneium
661                | SoneiumMinatoTestnet
662                | Odyssey
663                | World
664                | WorldSepolia
665                | Unichain
666                | UnichainSepolia
667                | HappychainTestnet
668        )
669    }
670
671    /// Returns true if the chain contains Arbitrum configuration.
672    pub const fn is_arbitrum(self) -> bool {
673        use NamedChain::*;
674
675        matches!(self, Arbitrum | ArbitrumTestnet | ArbitrumGoerli | ArbitrumSepolia | ArbitrumNova)
676    }
677
678    /// Returns true if the chain contains Elastic Network configuration.
679    pub const fn is_elastic(self) -> bool {
680        use NamedChain::*;
681
682        matches!(
683            self,
684            ZkSync
685                | ZkSyncTestnet
686                | Abstract
687                | AbstractTestnet
688                | Sophon
689                | SophonTestnet
690                | Lens
691                | LensTestnet
692        )
693    }
694
695    /// Returns the chain's average blocktime, if applicable.
696    ///
697    /// It can be beneficial to know the average blocktime to adjust the polling of an HTTP provider
698    /// for example.
699    ///
700    /// **Note:** this is not an accurate average, but is rather a sensible default derived from
701    /// blocktime charts such as [Etherscan's](https://etherscan.com/chart/blocktime)
702    /// or [Polygonscan's](https://polygonscan.com/chart/blocktime).
703    ///
704    /// # Examples
705    ///
706    /// ```
707    /// use alloy_chains::NamedChain;
708    /// use std::time::Duration;
709    ///
710    /// assert_eq!(NamedChain::Mainnet.average_blocktime_hint(), Some(Duration::from_millis(12_000)),);
711    /// assert_eq!(NamedChain::Optimism.average_blocktime_hint(), Some(Duration::from_millis(2_000)),);
712    /// ```
713    pub const fn average_blocktime_hint(self) -> Option<Duration> {
714        use NamedChain::*;
715
716        Some(Duration::from_millis(match self {
717            Mainnet | Taiko | TaikoHekla => 12_000,
718
719            Arbitrum
720            | ArbitrumTestnet
721            | ArbitrumGoerli
722            | ArbitrumSepolia
723            | GravityAlphaMainnet
724            | GravityAlphaTestnetSepolia
725            | Xai
726            | XaiSepolia
727            | Syndr
728            | SyndrSepolia
729            | ArbitrumNova
730            | ApeChain
731            | Curtis
732            | SuperpositionTestnet
733            | Superposition => 260,
734
735            Optimism | OptimismGoerli | OptimismSepolia | Base | BaseGoerli | BaseSepolia
736            | Blast | BlastSepolia | Fraxtal | FraxtalTestnet | Zora | ZoraSepolia | Mantle
737            | MantleSepolia | Mode | ModeSepolia | Pgn | PgnSepolia | HappychainTestnet
738            | Soneium | SoneiumMinatoTestnet | Bob | BobSepolia => 2_000,
739
740            Ink | InkSepolia | Odyssey => 1_000,
741
742            Viction => 2_000,
743
744            Polygon | PolygonMumbai | PolygonAmoy => 2_100,
745
746            Acala | AcalaMandalaTestnet | AcalaTestnet | Karura | KaruraTestnet | Moonbeam
747            | Moonriver => 12_500,
748
749            BinanceSmartChain | BinanceSmartChainTestnet => 3_000,
750
751            Avalanche | AvalancheFuji => 2_000,
752
753            Fantom | FantomTestnet => 1_200,
754
755            Cronos | CronosTestnet | Canto | CantoTestnet => 5_700,
756
757            Evmos | EvmosTestnet => 1_900,
758
759            Aurora | AuroraTestnet => 1_100,
760
761            Oasis => 5_500,
762
763            Emerald | Darwinia | Crab | Koi => 6_000,
764
765            Dev | AnvilHardhat => 200,
766
767            Celo | CeloAlfajores | CeloBaklava => 5_000,
768
769            FilecoinCalibrationTestnet | FilecoinMainnet => 30_000,
770
771            Scroll | ScrollSepolia => 3_000,
772
773            Shimmer => 5_000,
774
775            Gnosis | Chiado => 5_000,
776
777            Elastos => 5_000,
778
779            Etherlink => 5_000,
780
781            EtherlinkTestnet => 5_000,
782
783            Degen => 600,
784
785            Cfx | CfxTestnet => 500,
786
787            OpBNBMainnet | OpBNBTestnet | AutonomysNovaTestnet => 1_000,
788
789            Ronin | RoninTestnet => 3_000,
790
791            Flare => 1_800,
792
793            FlareCoston2 => 2_500,
794
795            Pulsechain => 10000,
796            PulsechainTestnet => 10101,
797
798            Immutable | ImmutableTestnet => 2_000,
799
800            World | WorldSepolia => 2_000,
801
802            Iotex => 5_000,
803            Core => 3_000,
804            Merlin => 3_000,
805            Bitlayer => 3_000,
806            Vana => 6_000,
807            Zeta => 6_000,
808            Kaia => 1_000,
809            Story => 2_500,
810            Sei => 500,
811
812            Sonic => 1_000,
813
814            TelosEvm | TelosEvmTestnet => 500,
815
816            UnichainSepolia | Unichain => 1_000,
817
818            BerachainBepolia | BerachainBartio | BerachainArtio | Berachain => 2_000,
819
820            MonadTestnet => 500,
821
822            Hyperliquid => 2_000,
823
824            Abstract | AbstractTestnet => 1_000,
825            ZkSync | ZkSyncTestnet => 1_000,
826            Sophon | SophonTestnet => 1_000,
827            Lens | LensTestnet => 1_000,
828
829            Morden | Ropsten | Rinkeby | Goerli | Kovan | Sepolia | Holesky | Hoodi
830            | MantleTestnet | Moonbase | MoonbeamDev | OptimismKovan | Poa | Sokol | Rsk
831            | RskTestnet | EmeraldTestnet | Boba | PolygonZkEvm | PolygonZkEvmTestnet | Metis
832            | Linea | LineaGoerli | LineaSepolia | KakarotSepolia | SonicBlaze | SonicTestnet
833            | Treasure | TreasureTopaz | Corn | CornTestnet => return None,
834        }))
835    }
836
837    /// Returns whether the chain implements EIP-1559 (with the type 2 EIP-2718 transaction type).
838    ///
839    /// # Examples
840    ///
841    /// ```
842    /// use alloy_chains::NamedChain;
843    ///
844    /// assert!(!NamedChain::Mainnet.is_legacy());
845    /// assert!(NamedChain::Fantom.is_legacy());
846    /// ```
847    pub const fn is_legacy(self) -> bool {
848        use NamedChain::*;
849
850        match self {
851            // Known legacy chains / non EIP-1559 compliant.
852            CeloAlfajores | CeloBaklava | Elastos | Emerald | EmeraldTestnet | Fantom
853            | FantomTestnet | MantleTestnet | OptimismKovan | PolygonZkEvm
854            | PolygonZkEvmTestnet | Ronin | RoninTestnet | Rsk | RskTestnet | Shimmer
855            | Treasure | TreasureTopaz | Viction | Sophon | SophonTestnet => true,
856
857            // Known EIP-1559 chains.
858            Mainnet
859            | Goerli
860            | Sepolia
861            | Holesky
862            | Hoodi
863            | Odyssey
864            | Acala
865            | AcalaMandalaTestnet
866            | AcalaTestnet
867            | ArbitrumTestnet
868            | Base
869            | BaseGoerli
870            | BaseSepolia
871            | Boba
872            | Metis
873            | Oasis
874            | Blast
875            | BlastSepolia
876            | Celo
877            | Fraxtal
878            | FraxtalTestnet
879            | Optimism
880            | OptimismGoerli
881            | OptimismSepolia
882            | Bob
883            | BobSepolia
884            | Polygon
885            | PolygonMumbai
886            | PolygonAmoy
887            | Avalanche
888            | AvalancheFuji
889            | Arbitrum
890            | ArbitrumGoerli
891            | ArbitrumSepolia
892            | ArbitrumNova
893            | GravityAlphaMainnet
894            | GravityAlphaTestnetSepolia
895            | Xai
896            | XaiSepolia
897            | HappychainTestnet
898            | Syndr
899            | SyndrSepolia
900            | FilecoinMainnet
901            | Linea
902            | LineaGoerli
903            | LineaSepolia
904            | FilecoinCalibrationTestnet
905            | Gnosis
906            | Chiado
907            | Zora
908            | ZoraSepolia
909            | Ink
910            | InkSepolia
911            | Mantle
912            | MantleSepolia
913            | Mode
914            | ModeSepolia
915            | Pgn
916            | PgnSepolia
917            | KakarotSepolia
918            | Etherlink
919            | EtherlinkTestnet
920            | Degen
921            | OpBNBMainnet
922            | OpBNBTestnet
923            | Taiko
924            | TaikoHekla
925            | AutonomysNovaTestnet
926            | Flare
927            | FlareCoston2
928            | Scroll
929            | ScrollSepolia
930            | Darwinia
931            | Cfx
932            | CfxTestnet
933            | Crab
934            | Pulsechain
935            | PulsechainTestnet
936            | Koi
937            | Immutable
938            | ImmutableTestnet
939            | Soneium
940            | SoneiumMinatoTestnet
941            | Sonic
942            | World
943            | WorldSepolia
944            | Unichain
945            | UnichainSepolia
946            | ApeChain
947            | BerachainBepolia
948            | BerachainBartio
949            | BerachainArtio
950            | Berachain
951            | Curtis
952            | SuperpositionTestnet
953            | Superposition
954            | MonadTestnet
955            | Hyperliquid
956            | Corn
957            | CornTestnet
958            | ZkSync
959            | ZkSyncTestnet
960            | AbstractTestnet
961            | Abstract
962            | Lens
963            | LensTestnet
964            | BinanceSmartChain
965            | BinanceSmartChainTestnet
966            | Karura
967            | KaruraTestnet
968            | TelosEvm
969            | TelosEvmTestnet => false,
970
971            // Unknown / not applicable, default to false for backwards compatibility.
972            Dev | AnvilHardhat | Morden | Ropsten | Rinkeby | Cronos | CronosTestnet | Kovan
973            | Sokol | Poa | Moonbeam | MoonbeamDev | Moonriver | Moonbase | Evmos
974            | EvmosTestnet | Aurora | AuroraTestnet | Canto | CantoTestnet | Iotex | Core
975            | Merlin | Bitlayer | SonicBlaze | SonicTestnet | Vana | Zeta | Kaia | Story | Sei => {
976                false
977            }
978        }
979    }
980
981    /// Returns whether the chain supports the [Shanghai hardfork][ref].
982    ///
983    /// [ref]: https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md
984    pub const fn supports_shanghai(self) -> bool {
985        use NamedChain::*;
986
987        matches!(
988            self,
989            Mainnet
990                | Goerli
991                | Sepolia
992                | Holesky
993                | Hoodi
994                | AnvilHardhat
995                | Optimism
996                | OptimismGoerli
997                | OptimismSepolia
998                | Bob
999                | BobSepolia
1000                | Odyssey
1001                | Base
1002                | BaseGoerli
1003                | BaseSepolia
1004                | Blast
1005                | BlastSepolia
1006                | Fraxtal
1007                | FraxtalTestnet
1008                | Ink
1009                | InkSepolia
1010                | Gnosis
1011                | Chiado
1012                | ZoraSepolia
1013                | Mantle
1014                | MantleSepolia
1015                | Mode
1016                | ModeSepolia
1017                | PolygonMumbai
1018                | Polygon
1019                | Arbitrum
1020                | ArbitrumNova
1021                | ArbitrumSepolia
1022                | GravityAlphaMainnet
1023                | GravityAlphaTestnetSepolia
1024                | Xai
1025                | XaiSepolia
1026                | Syndr
1027                | SyndrSepolia
1028                | Etherlink
1029                | EtherlinkTestnet
1030                | Scroll
1031                | ScrollSepolia
1032                | HappychainTestnet
1033                | Shimmer
1034                | BinanceSmartChain
1035                | BinanceSmartChainTestnet
1036                | OpBNBMainnet
1037                | OpBNBTestnet
1038                | KakarotSepolia
1039                | Taiko
1040                | TaikoHekla
1041                | Avalanche
1042                | AvalancheFuji
1043                | AutonomysNovaTestnet
1044                | Acala
1045                | AcalaMandalaTestnet
1046                | AcalaTestnet
1047                | Karura
1048                | KaruraTestnet
1049                | Darwinia
1050                | Crab
1051                | Cfx
1052                | CfxTestnet
1053                | Pulsechain
1054                | PulsechainTestnet
1055                | Koi
1056                | Immutable
1057                | ImmutableTestnet
1058                | Soneium
1059                | SoneiumMinatoTestnet
1060                | World
1061                | WorldSepolia
1062                | Iotex
1063                | Unichain
1064                | UnichainSepolia
1065                | ApeChain
1066                | Curtis
1067                | SuperpositionTestnet
1068                | Superposition
1069                | MonadTestnet
1070                | Corn
1071                | CornTestnet
1072        )
1073    }
1074
1075    #[doc(hidden)]
1076    #[deprecated(since = "0.1.3", note = "use `supports_shanghai` instead")]
1077    pub const fn supports_push0(self) -> bool {
1078        self.supports_shanghai()
1079    }
1080
1081    /// Returns whether the chain is a testnet.
1082    pub const fn is_testnet(self) -> bool {
1083        use NamedChain::*;
1084
1085        match self {
1086            // Ethereum testnets.
1087            Goerli | Holesky | Kovan | Sepolia | Morden | Ropsten | Rinkeby | Hoodi => true,
1088
1089            // Other testnets.
1090            ArbitrumGoerli
1091            | ArbitrumSepolia
1092            | ArbitrumTestnet
1093            | SyndrSepolia
1094            | AuroraTestnet
1095            | AvalancheFuji
1096            | Odyssey
1097            | BaseGoerli
1098            | BaseSepolia
1099            | BlastSepolia
1100            | BinanceSmartChainTestnet
1101            | CantoTestnet
1102            | CronosTestnet
1103            | CeloAlfajores
1104            | CeloBaklava
1105            | EmeraldTestnet
1106            | EvmosTestnet
1107            | FantomTestnet
1108            | FilecoinCalibrationTestnet
1109            | FraxtalTestnet
1110            | HappychainTestnet
1111            | LineaGoerli
1112            | LineaSepolia
1113            | InkSepolia
1114            | MantleTestnet
1115            | MantleSepolia
1116            | MoonbeamDev
1117            | OptimismGoerli
1118            | OptimismKovan
1119            | OptimismSepolia
1120            | BobSepolia
1121            | PolygonMumbai
1122            | PolygonAmoy
1123            | PolygonZkEvmTestnet
1124            | ScrollSepolia
1125            | Shimmer
1126            | ZkSyncTestnet
1127            | ZoraSepolia
1128            | ModeSepolia
1129            | PgnSepolia
1130            | KakarotSepolia
1131            | EtherlinkTestnet
1132            | OpBNBTestnet
1133            | RoninTestnet
1134            | TaikoHekla
1135            | AutonomysNovaTestnet
1136            | FlareCoston2
1137            | AcalaMandalaTestnet
1138            | AcalaTestnet
1139            | KaruraTestnet
1140            | CfxTestnet
1141            | PulsechainTestnet
1142            | GravityAlphaTestnetSepolia
1143            | XaiSepolia
1144            | Koi
1145            | ImmutableTestnet
1146            | SoneiumMinatoTestnet
1147            | WorldSepolia
1148            | UnichainSepolia
1149            | Curtis
1150            | TreasureTopaz
1151            | SonicBlaze
1152            | SonicTestnet
1153            | BerachainBepolia
1154            | BerachainBartio
1155            | BerachainArtio
1156            | SuperpositionTestnet
1157            | MonadTestnet
1158            | RskTestnet
1159            | TelosEvmTestnet
1160            | AbstractTestnet
1161            | LensTestnet
1162            | SophonTestnet
1163            | CornTestnet => true,
1164
1165            // Dev chains.
1166            Dev | AnvilHardhat => true,
1167
1168            // Mainnets.
1169            Mainnet | Optimism | Arbitrum | ArbitrumNova | Blast | Syndr | Cronos | Rsk
1170            | BinanceSmartChain | Poa | Sokol | Scroll | Metis | Gnosis | Polygon
1171            | PolygonZkEvm | Fantom | Moonbeam | Moonriver | Moonbase | Evmos | Chiado | Oasis
1172            | Emerald | FilecoinMainnet | Avalanche | Celo | Aurora | Canto | Boba | Base
1173            | Fraxtal | Ink | Linea | ZkSync | Mantle | GravityAlphaMainnet | Xai | Zora | Pgn
1174            | Mode | Viction | Elastos | Degen | OpBNBMainnet | Ronin | Taiko | Flare | Acala
1175            | Karura | Darwinia | Cfx | Crab | Pulsechain | Etherlink | Immutable | World
1176            | Iotex | Core | Merlin | Bitlayer | ApeChain | Vana | Zeta | Kaia | Treasure | Bob
1177            | Soneium | Sonic | Superposition | Berachain | Unichain | TelosEvm | Story | Sei
1178            | Hyperliquid | Abstract | Sophon | Lens | Corn => false,
1179        }
1180    }
1181
1182    /// Returns the symbol of the chain's native currency.
1183    pub const fn native_currency_symbol(self) -> Option<&'static str> {
1184        use NamedChain::*;
1185
1186        Some(match self {
1187            Mainnet | Goerli | Holesky | Kovan | Sepolia | Morden | Ropsten | Rinkeby | Scroll
1188            | ScrollSepolia | Taiko | TaikoHekla | Unichain | UnichainSepolia
1189            | SuperpositionTestnet | Superposition | Abstract | ZkSync | ZkSyncTestnet => "ETH",
1190
1191            Mantle | MantleSepolia => "MNT",
1192
1193            GravityAlphaMainnet | GravityAlphaTestnetSepolia => "G",
1194
1195            Xai | XaiSepolia => "XAI",
1196
1197            HappychainTestnet => "HAPPY",
1198
1199            BinanceSmartChain | BinanceSmartChainTestnet | OpBNBMainnet | OpBNBTestnet => "BNB",
1200
1201            Etherlink | EtherlinkTestnet => "XTZ",
1202
1203            Degen => "DEGEN",
1204
1205            Ronin | RoninTestnet => "RON",
1206
1207            Shimmer => "SMR",
1208
1209            Flare => "FLR",
1210
1211            FlareCoston2 => "C2FLR",
1212
1213            Darwinia => "RING",
1214
1215            Crab => "CRAB",
1216
1217            Koi => "KRING",
1218
1219            Cfx | CfxTestnet => "CFX",
1220            Pulsechain | PulsechainTestnet => "PLS",
1221
1222            Immutable => "IMX",
1223            ImmutableTestnet => "tIMX",
1224
1225            World | WorldSepolia => "WRLD",
1226
1227            Iotex => "IOTX",
1228            Core => "CORE",
1229            Merlin => "BTC",
1230            Bitlayer => "BTC",
1231            Vana => "VANA",
1232            Zeta => "ZETA",
1233            Kaia => "KAIA",
1234            Story => "IP",
1235            Sei => "SEI",
1236            ApeChain | Curtis => "APE",
1237
1238            Treasure | TreasureTopaz => "MAGIC",
1239
1240            BerachainBepolia | BerachainBartio | BerachainArtio | Berachain => "BERA",
1241
1242            Sonic | SonicBlaze => "S",
1243
1244            TelosEvm | TelosEvmTestnet => "TLOS",
1245
1246            Hyperliquid => "HYPE",
1247
1248            Polygon | PolygonMumbai | PolygonZkEvm | PolygonZkEvmTestnet | PolygonAmoy => "POL",
1249
1250            Corn | CornTestnet => "BTCN",
1251
1252            Sophon | SophonTestnet => "SOPH",
1253
1254            LensTestnet => "GRASS",
1255            Lens => "GHO",
1256
1257            _ => return None,
1258        })
1259    }
1260
1261    /// Returns the chain's blockchain explorer and its API (Etherscan and Etherscan-like) URLs.
1262    ///
1263    /// Returns `(API_URL, BASE_URL)`.
1264    ///
1265    /// All URLs have no trailing `/`
1266    ///
1267    /// # Examples
1268    ///
1269    /// ```
1270    /// use alloy_chains::NamedChain;
1271    ///
1272    /// assert_eq!(
1273    ///     NamedChain::Mainnet.etherscan_urls(),
1274    ///     Some(("https://api.etherscan.io/api", "https://etherscan.io"))
1275    /// );
1276    /// assert_eq!(
1277    ///     NamedChain::Avalanche.etherscan_urls(),
1278    ///     Some(("https://api.snowtrace.io/api", "https://snowtrace.io"))
1279    /// );
1280    /// assert_eq!(NamedChain::AnvilHardhat.etherscan_urls(), None);
1281    /// ```
1282    pub const fn etherscan_urls(self) -> Option<(&'static str, &'static str)> {
1283        use NamedChain::*;
1284
1285        Some(match self {
1286            Mainnet => ("https://api.etherscan.io/api", "https://etherscan.io"),
1287            Ropsten => ("https://api-ropsten.etherscan.io/api", "https://ropsten.etherscan.io"),
1288            Kovan => ("https://api-kovan.etherscan.io/api", "https://kovan.etherscan.io"),
1289            Rinkeby => ("https://api-rinkeby.etherscan.io/api", "https://rinkeby.etherscan.io"),
1290            Goerli => ("https://api-goerli.etherscan.io/api", "https://goerli.etherscan.io"),
1291            Sepolia => ("https://api-sepolia.etherscan.io/api", "https://sepolia.etherscan.io"),
1292            Holesky => ("https://api-holesky.etherscan.io/api", "https://holesky.etherscan.io"),
1293            Hoodi => ("https://api-hoodi.etherscan.io/api", "https://hoodi.etherscan.io"),
1294
1295            Polygon => ("https://api.polygonscan.com/api", "https://polygonscan.com"),
1296            PolygonMumbai => {
1297                ("https://api-testnet.polygonscan.com/api", "https://mumbai.polygonscan.com")
1298            }
1299            PolygonAmoy => ("https://api-amoy.polygonscan.com/api", "https://amoy.polygonscan.com"),
1300
1301            PolygonZkEvm => {
1302                ("https://api-zkevm.polygonscan.com/api", "https://zkevm.polygonscan.com")
1303            }
1304            PolygonZkEvmTestnet => (
1305                "https://api-testnet-zkevm.polygonscan.com/api",
1306                "https://testnet-zkevm.polygonscan.com",
1307            ),
1308
1309            Avalanche => ("https://api.snowtrace.io/api", "https://snowtrace.io"),
1310            AvalancheFuji => {
1311                ("https://api-testnet.snowtrace.io/api", "https://testnet.snowtrace.io")
1312            }
1313
1314            Optimism => {
1315                ("https://api-optimistic.etherscan.io/api", "https://optimistic.etherscan.io")
1316            }
1317            OptimismGoerli => (
1318                "https://api-goerli-optimistic.etherscan.io/api",
1319                "https://goerli-optimism.etherscan.io",
1320            ),
1321            OptimismKovan => (
1322                "https://api-kovan-optimistic.etherscan.io/api",
1323                "https://kovan-optimistic.etherscan.io",
1324            ),
1325            OptimismSepolia => (
1326                "https://api-sepolia-optimistic.etherscan.io/api",
1327                "https://sepolia-optimism.etherscan.io",
1328            ),
1329
1330            Bob => ("https://explorer.gobob.xyz/api", "https://explorer.gobob.xyz"),
1331            BobSepolia => (
1332                "https://bob-sepolia.explorer.gobob.xyz/api",
1333                "https://bob-sepolia.explorer.gobob.xyz",
1334            ),
1335
1336            Fantom => ("https://api.ftmscan.com/api", "https://ftmscan.com"),
1337            FantomTestnet => ("https://api-testnet.ftmscan.com/api", "https://testnet.ftmscan.com"),
1338
1339            BinanceSmartChain => ("https://api.bscscan.com/api", "https://bscscan.com"),
1340            BinanceSmartChainTestnet => {
1341                ("https://api-testnet.bscscan.com/api", "https://testnet.bscscan.com")
1342            }
1343
1344            OpBNBMainnet => ("https://opbnb.bscscan.com/api", "https://opbnb.bscscan.com"),
1345            OpBNBTestnet => {
1346                ("https://opbnb-testnet.bscscan.com/api", "https://opbnb-testnet.bscscan.com")
1347            }
1348
1349            Arbitrum => ("https://api.arbiscan.io/api", "https://arbiscan.io"),
1350            ArbitrumTestnet => {
1351                ("https://api-testnet.arbiscan.io/api", "https://testnet.arbiscan.io")
1352            }
1353            ArbitrumGoerli => ("https://api-goerli.arbiscan.io/api", "https://goerli.arbiscan.io"),
1354            ArbitrumSepolia => {
1355                ("https://api-sepolia.arbiscan.io/api", "https://sepolia.arbiscan.io")
1356            }
1357            ArbitrumNova => ("https://api-nova.arbiscan.io/api", "https://nova.arbiscan.io"),
1358
1359            GravityAlphaMainnet => {
1360                ("https://explorer.gravity.xyz/api", "https://explorer.gravity.xyz")
1361            }
1362            GravityAlphaTestnetSepolia => {
1363                ("https://explorer-sepolia.gravity.xyz/api", "https://explorer-sepolia.gravity.xyz")
1364            }
1365            HappychainTestnet => {
1366                ("https://explorer.testnet.happy.tech/api", "https://explorer.testnet.happy.tech")
1367            }
1368
1369            XaiSepolia => ("https://sepolia.xaiscan.io/api", "https://sepolia.xaiscan.io"),
1370            Xai => ("https://xaiscan.io/api", "https://xaiscan.io"),
1371
1372            Syndr => ("https://explorer.syndr.com/api", "https://explorer.syndr.com"),
1373            SyndrSepolia => {
1374                ("https://sepolia-explorer.syndr.com/api", "https://sepolia-explorer.syndr.com")
1375            }
1376
1377            Cronos => ("https://api.cronoscan.com/api", "https://cronoscan.com"),
1378            CronosTestnet => {
1379                ("https://api-testnet.cronoscan.com/api", "https://testnet.cronoscan.com")
1380            }
1381
1382            Moonbeam => ("https://api-moonbeam.moonscan.io/api", "https://moonbeam.moonscan.io"),
1383            Moonbase => ("https://api-moonbase.moonscan.io/api", "https://moonbase.moonscan.io"),
1384            Moonriver => ("https://api-moonriver.moonscan.io/api", "https://moonriver.moonscan.io"),
1385
1386            Gnosis => ("https://api.gnosisscan.io/api", "https://gnosisscan.io"),
1387
1388            Scroll => ("https://api.scrollscan.com/api", "https://scrollscan.com"),
1389            ScrollSepolia => {
1390                ("https://api-sepolia.scrollscan.com/api", "https://sepolia.scrollscan.com")
1391            }
1392
1393            Ink => ("https://explorer.inkonchain.com/api/v2", "https://explorer.inkonchain.com"),
1394            InkSepolia => (
1395                "https://explorer-sepolia.inkonchain.com/api/v2",
1396                "https://explorer-sepolia.inkonchain.com",
1397            ),
1398
1399            Shimmer => {
1400                ("https://explorer.evm.shimmer.network/api", "https://explorer.evm.shimmer.network")
1401            }
1402
1403            Metis => (
1404                "https://api.routescan.io/v2/network/mainnet/evm/1088/etherscan",
1405                "https://explorer.metis.io",
1406            ),
1407
1408            Chiado => {
1409                ("https://blockscout.chiadochain.net/api", "https://blockscout.chiadochain.net")
1410            }
1411
1412            FilecoinCalibrationTestnet => (
1413                "https://api.calibration.node.glif.io/rpc/v1",
1414                "https://calibration.filfox.info/en",
1415            ),
1416
1417            Sokol => ("https://blockscout.com/poa/sokol/api", "https://blockscout.com/poa/sokol"),
1418
1419            Poa => ("https://blockscout.com/poa/core/api", "https://blockscout.com/poa/core"),
1420
1421            Rsk => ("https://blockscout.com/rsk/mainnet/api", "https://blockscout.com/rsk/mainnet"),
1422            RskTestnet => (
1423                "https://rootstock-testnet.blockscout.com/api",
1424                "https://rootstock-testnet.blockscout.com",
1425            ),
1426
1427            Oasis => ("https://scan.oasischain.io/api", "https://scan.oasischain.io"),
1428
1429            Emerald => {
1430                ("https://explorer.emerald.oasis.dev/api", "https://explorer.emerald.oasis.dev")
1431            }
1432            EmeraldTestnet => (
1433                "https://testnet.explorer.emerald.oasis.dev/api",
1434                "https://testnet.explorer.emerald.oasis.dev",
1435            ),
1436
1437            Aurora => ("https://api.aurorascan.dev/api", "https://aurorascan.dev"),
1438            AuroraTestnet => {
1439                ("https://testnet.aurorascan.dev/api", "https://testnet.aurorascan.dev")
1440            }
1441
1442            Evmos => ("https://evm.evmos.org/api", "https://evm.evmos.org"),
1443            EvmosTestnet => ("https://evm.evmos.dev/api", "https://evm.evmos.dev"),
1444
1445            Celo => ("https://api.celoscan.io/api", "https://celoscan.io"),
1446            CeloAlfajores => {
1447                ("https://api-alfajores.celoscan.io/api", "https://alfajores.celoscan.io")
1448            }
1449            CeloBaklava => {
1450                ("https://explorer.celo.org/baklava/api", "https://explorer.celo.org/baklava")
1451            }
1452
1453            Canto => ("https://evm.explorer.canto.io/api", "https://evm.explorer.canto.io"),
1454            CantoTestnet => (
1455                "https://testnet-explorer.canto.neobase.one/api",
1456                "https://testnet-explorer.canto.neobase.one",
1457            ),
1458
1459            Boba => ("https://api.bobascan.com/api", "https://bobascan.com"),
1460
1461            Base => ("https://api.basescan.org/api", "https://basescan.org"),
1462            BaseGoerli => ("https://api-goerli.basescan.org/api", "https://goerli.basescan.org"),
1463            BaseSepolia => ("https://api-sepolia.basescan.org/api", "https://sepolia.basescan.org"),
1464
1465            Fraxtal => ("https://api.fraxscan.com/api", "https://fraxscan.com"),
1466            FraxtalTestnet => {
1467                ("https://api-holesky.fraxscan.com/api", "https://holesky.fraxscan.com")
1468            }
1469
1470            Blast => ("https://api.blastscan.io/api", "https://blastscan.io"),
1471            BlastSepolia => {
1472                ("https://api-sepolia.blastscan.io/api", "https://sepolia.blastscan.io")
1473            }
1474
1475            ZkSync => ("https://api-era.zksync.network/api", "https://era.zksync.network"),
1476            ZkSyncTestnet => {
1477                ("https://api-sepolia-era.zksync.network/api", "https://sepolia-era.zksync.network")
1478            }
1479
1480            Linea => ("https://api.lineascan.build/api", "https://lineascan.build"),
1481            LineaGoerli => {
1482                ("https://explorer.goerli.linea.build/api", "https://explorer.goerli.linea.build")
1483            }
1484            LineaSepolia => {
1485                ("https://api-sepolia.lineascan.build/api", "https://sepolia.lineascan.build")
1486            }
1487
1488            Mantle => ("https://explorer.mantle.xyz/api", "https://explorer.mantle.xyz"),
1489            MantleTestnet => {
1490                ("https://explorer.testnet.mantle.xyz/api", "https://explorer.testnet.mantle.xyz")
1491            }
1492            MantleSepolia => {
1493                ("https://explorer.sepolia.mantle.xyz/api", "https://explorer.sepolia.mantle.xyz")
1494            }
1495
1496            Viction => ("https://www.vicscan.xyz/api", "https://www.vicscan.xyz"),
1497
1498            Zora => ("https://explorer.zora.energy/api", "https://explorer.zora.energy"),
1499            ZoraSepolia => {
1500                ("https://sepolia.explorer.zora.energy/api", "https://sepolia.explorer.zora.energy")
1501            }
1502
1503            Pgn => {
1504                ("https://explorer.publicgoods.network/api", "https://explorer.publicgoods.network")
1505            }
1506
1507            PgnSepolia => (
1508                "https://explorer.sepolia.publicgoods.network/api",
1509                "https://explorer.sepolia.publicgoods.network",
1510            ),
1511
1512            Mode => ("https://explorer.mode.network/api", "https://explorer.mode.network"),
1513            ModeSepolia => (
1514                "https://sepolia.explorer.mode.network/api",
1515                "https://sepolia.explorer.mode.network",
1516            ),
1517
1518            Elastos => ("https://esc.elastos.io/api", "https://esc.elastos.io"),
1519            KakarotSepolia => {
1520                ("https://sepolia.kakarotscan.org/api", "https://sepolia.kakarotscan.org")
1521            }
1522            Etherlink => ("https://explorer.etherlink.com/api", "https://explorer.etherlink.com"),
1523            EtherlinkTestnet => (
1524                "https://testnet-explorer.etherlink.com/api",
1525                "https://testnet-explorer.etherlink.com",
1526            ),
1527            Degen => ("https://explorer.degen.tips/api", "https://explorer.degen.tips"),
1528            Ronin => ("https://skynet-api.roninchain.com/ronin", "https://app.roninchain.com"),
1529            RoninTestnet => (
1530                "https://api-gateway.skymavis.com/rpc/testnet",
1531                "https://saigon-app.roninchain.com",
1532            ),
1533            Taiko => ("https://api.taikoscan.io/api", "https://taikoscan.io"),
1534            TaikoHekla => ("https://api-testnet.taikoscan.io/api", "https://hekla.taikoscan.io"),
1535            Flare => {
1536                ("https://flare-explorer.flare.network/api", "https://flare-explorer.flare.network")
1537            }
1538            FlareCoston2 => (
1539                "https://coston2-explorer.flare.network/api",
1540                "https://coston2-explorer.flare.network",
1541            ),
1542            Acala => ("https://blockscout.acala.network/api", "https://blockscout.acala.network"),
1543            AcalaMandalaTestnet => (
1544                "https://blockscout.mandala.aca-staging.network/api",
1545                "https://blockscout.mandala.aca-staging.network",
1546            ),
1547            AcalaTestnet => (
1548                "https://blockscout.acala-testnet.aca-staging.network/api",
1549                "https://blockscout.acala-testnet.aca-staging.network",
1550            ),
1551            Karura => {
1552                ("https://blockscout.karura.network/api", "https://blockscout.karura.network")
1553            }
1554            KaruraTestnet => (
1555                "https://blockscout.karura-testnet.aca-staging.network/api",
1556                "https://blockscout.karura-testnet.aca-staging.network",
1557            ),
1558
1559            Darwinia => {
1560                ("https://explorer.darwinia.network/api", "https://explorer.darwinia.network")
1561            }
1562            Crab => {
1563                ("https://crab-scan.darwinia.network/api", "https://crab-scan.darwinia.network")
1564            }
1565            Koi => ("https://koi-scan.darwinia.network/api", "https://koi-scan.darwinia.network"),
1566            Cfx => ("https://evmapi.confluxscan.net/api", "https://evm.confluxscan.io"),
1567            CfxTestnet => {
1568                ("https://evmapi-testnet.confluxscan.net/api", "https://evmtestnet.confluxscan.io")
1569            }
1570            Pulsechain => ("https://api.scan.pulsechain.com", "https://scan.pulsechain.com"),
1571            PulsechainTestnet => (
1572                "https://api.scan.v4.testnet.pulsechain.com",
1573                "https://scan.v4.testnet.pulsechain.com",
1574            ),
1575
1576            Immutable => ("https://explorer.immutable.com/api", "https://explorer.immutable.com"),
1577            ImmutableTestnet => (
1578                "https://explorer.testnet.immutable.com/api",
1579                "https://explorer.testnet.immutable.com",
1580            ),
1581            Soneium => ("https://soneium.blockscout.com/api", "https://soneium.blockscout.com"),
1582            SoneiumMinatoTestnet => (
1583                "https://soneium-minato.blockscout.com/api",
1584                "https://soneium-minato.blockscout.com",
1585            ),
1586            Odyssey => {
1587                ("https://odyssey-explorer.ithaca.xyz/api", "https://odyssey-explorer.ithaca.xyz")
1588            }
1589            World => ("https://api.worldscan.org/api", "https://worldscan.org"),
1590            WorldSepolia => {
1591                ("https://api-sepolia.worldscan.org/api", "https://sepolia.worldscan.org")
1592            }
1593            Unichain => ("https://api.uniscan.xyz/api", "https://uniscan.xyz"),
1594            UnichainSepolia => {
1595                ("https://api-sepolia.uniscan.xyz/api", "https://sepolia.uniscan.xyz")
1596            }
1597            Core => ("https://openapi.coredao.org/api", "https://scan.coredao.org"),
1598            Merlin => ("https://scan.merlinchain.io/api", "https://scan.merlinchain.io"),
1599            Bitlayer => ("https://api.btrscan.com/scan/api", "https://www.btrscan.com"),
1600            Vana => ("https://api.vanascan.io/api", "https://vanascan.io"),
1601            Zeta => ("https://zetachain.blockscout.com/api", "https://zetachain.blockscout.com"),
1602            Kaia => ("https://mainnet-oapi.kaiascan.io/api", "https://kaiascan.io"),
1603            Story => ("https://www.storyscan.xyz/api/v2", "https://www.storyscan.xyz"),
1604
1605            ApeChain => ("https://api.apescan.io/api", "https://apescan.io"),
1606            Curtis => ("https://curtis.explorer.caldera.xyz/api/v2", "https://curtis.apescan.io"),
1607            SonicBlaze => {
1608                ("https://api-testnet.sonicscan.org/api", "https://testnet.sonicscan.org")
1609            }
1610            SonicTestnet => (
1611                "https://api.routescan.io/v2/network/testnet/evm/64165/etherscan/api",
1612                "https://scan.soniclabs.com",
1613            ),
1614            Sonic => ("https://api.sonicscan.org/api", "https://sonicscan.org"),
1615            Treasure => ("https://block-explorer.treasurescan.io/api", "https://treasurescan.io"),
1616            TreasureTopaz => (
1617                "https://block-explorer.topaz.treasurescan.io/api",
1618                "https://topaz.treasurescan.io",
1619            ),
1620            BerachainBepolia => {
1621                ("https://bepolia.beratrail.io/api", "https://bepolia.beratrail.io")
1622            }
1623            BerachainBartio => ("https://bartio.beratrail.io/api", "https://bartio.beratrail.io"),
1624            BerachainArtio => ("https://artio.beratrail.io/api", "https://artio.beratrail.io"),
1625            Berachain => ("https://api.berascan.com/api", "https://berascan.com"),
1626            SuperpositionTestnet => (
1627                "https://testnet-explorer.superposition.so/api",
1628                "https://testnet-explorer.superposition.so",
1629            ),
1630            Superposition => {
1631                ("https://explorer.superposition.so/api", "https://explorer.superposition.so")
1632            }
1633            MonadTestnet => ("https://sourcify.dev/server", "https://testnet.monadexplorer.com"),
1634            TelosEvm => ("https://api.teloscan.io/api", "https://teloscan.io"),
1635            TelosEvmTestnet => {
1636                ("https://api.testnet.teloscan.io/api", "https://testnet.teloscan.io")
1637            }
1638            Hyperliquid => (
1639                "https://hyperliquid.cloud.blockscout.com/api/v2",
1640                "https://hyperliquid.cloud.blockscout.com",
1641            ),
1642            Abstract => ("https://api.abscan.org/api", "https://abscan.org"),
1643            AbstractTestnet => ("https://api-testnet.abscan.org/api", "https://sepolia.abscan.org"),
1644            Corn => (
1645                "https://api.routescan.io/v2/network/mainnet/evm/21000000/etherscan/api",
1646                "https://cornscan.io",
1647            ),
1648            CornTestnet => (
1649                "https://api.routescan.io/v2/network/testnet/evm/21000001/etherscan/api",
1650                "https://testnet.cornscan.io",
1651            ),
1652            // TODO: add hoodi etherscan when live
1653            AnvilHardhat | Dev | Morden | MoonbeamDev | FilecoinMainnet | AutonomysNovaTestnet
1654            | Iotex | Sei => {
1655                return None;
1656            }
1657            Sophon => ("https://api.sophscan.xyz/api", "https://sophscan.xyz"),
1658            SophonTestnet => {
1659                ("https://api-sepolia.sophscan.xyz/api", "https://testnet.sophscan.xyz")
1660            }
1661            Lens => ("https://explorer-api.lens.xyz", "https://explorer.lens.xyz"),
1662            LensTestnet => (
1663                "https://block-explorer-api.staging.lens.zksync.dev",
1664                "https://explorer.testnet.lens.xyz",
1665            ),
1666        })
1667    }
1668
1669    /// Returns the chain's blockchain explorer's API key environment variable's default name.
1670    ///
1671    /// # Examples
1672    ///
1673    /// ```
1674    /// use alloy_chains::NamedChain;
1675    ///
1676    /// assert_eq!(NamedChain::Mainnet.etherscan_api_key_name(), Some("ETHERSCAN_API_KEY"));
1677    /// assert_eq!(NamedChain::AnvilHardhat.etherscan_api_key_name(), None);
1678    /// ```
1679    pub const fn etherscan_api_key_name(self) -> Option<&'static str> {
1680        use NamedChain::*;
1681
1682        let api_key_name = match self {
1683            Mainnet
1684            | Morden
1685            | Ropsten
1686            | Kovan
1687            | Rinkeby
1688            | Goerli
1689            | Holesky
1690            | Hoodi
1691            | Optimism
1692            | OptimismGoerli
1693            | OptimismKovan
1694            | OptimismSepolia
1695            | BinanceSmartChain
1696            | BinanceSmartChainTestnet
1697            | OpBNBMainnet
1698            | OpBNBTestnet
1699            | Arbitrum
1700            | ArbitrumTestnet
1701            | ArbitrumGoerli
1702            | ArbitrumSepolia
1703            | ArbitrumNova
1704            | Syndr
1705            | SyndrSepolia
1706            | Cronos
1707            | CronosTestnet
1708            | Aurora
1709            | AuroraTestnet
1710            | Celo
1711            | CeloAlfajores
1712            | Base
1713            | Linea
1714            | LineaSepolia
1715            | Mantle
1716            | MantleTestnet
1717            | MantleSepolia
1718            | Xai
1719            | XaiSepolia
1720            | BaseGoerli
1721            | BaseSepolia
1722            | Fraxtal
1723            | FraxtalTestnet
1724            | Blast
1725            | BlastSepolia
1726            | Gnosis
1727            | Scroll
1728            | ScrollSepolia
1729            | Taiko
1730            | TaikoHekla
1731            | Unichain
1732            | UnichainSepolia
1733            | MonadTestnet
1734            | ApeChain
1735            | Abstract
1736            | AbstractTestnet
1737            | ZkSyncTestnet
1738            | ZkSync
1739            | Sophon
1740            | SophonTestnet => "ETHERSCAN_API_KEY",
1741
1742            Avalanche | AvalancheFuji => "SNOWTRACE_API_KEY",
1743
1744            Polygon | PolygonMumbai | PolygonAmoy | PolygonZkEvm | PolygonZkEvmTestnet => {
1745                "POLYGONSCAN_API_KEY"
1746            }
1747
1748            Fantom | FantomTestnet => "FTMSCAN_API_KEY",
1749
1750            Moonbeam | Moonbase | MoonbeamDev | Moonriver => "MOONSCAN_API_KEY",
1751
1752            Acala | AcalaMandalaTestnet | AcalaTestnet | Canto | CantoTestnet | CeloBaklava
1753            | Etherlink | EtherlinkTestnet | Flare | FlareCoston2 | KakarotSepolia | Karura
1754            | KaruraTestnet | Mode | ModeSepolia | Pgn | PgnSepolia | Shimmer | Zora
1755            | ZoraSepolia | Darwinia | Crab | Koi | Immutable | ImmutableTestnet | Soneium
1756            | SoneiumMinatoTestnet | World | WorldSepolia | Curtis | Ink | InkSepolia
1757            | SuperpositionTestnet | Superposition | Vana | Story | Hyperliquid => {
1758                "BLOCKSCOUT_API_KEY"
1759            }
1760
1761            Boba => "BOBASCAN_API_KEY",
1762
1763            Core => "CORESCAN_API_KEY",
1764            Merlin => "MERLINSCAN_API_KEY",
1765            Bitlayer => "BITLAYERSCAN_API_KEY",
1766            Zeta => "ZETASCAN_API_KEY",
1767            Kaia => "KAIASCAN_API_KEY",
1768            Sonic => "SONICSCAN_API_KEY",
1769            Berachain => "BERASCAN_API_KEY",
1770            Corn | CornTestnet => "ROUTESCAN_API_KEY",
1771            // Explicitly exhaustive. See NB above.
1772            Metis
1773            | Chiado
1774            | Odyssey
1775            | Sepolia
1776            | Rsk
1777            | RskTestnet
1778            | Sokol
1779            | Poa
1780            | Oasis
1781            | Emerald
1782            | EmeraldTestnet
1783            | Evmos
1784            | EvmosTestnet
1785            | AnvilHardhat
1786            | Dev
1787            | GravityAlphaMainnet
1788            | GravityAlphaTestnetSepolia
1789            | Bob
1790            | BobSepolia
1791            | FilecoinMainnet
1792            | LineaGoerli
1793            | FilecoinCalibrationTestnet
1794            | Viction
1795            | Elastos
1796            | Degen
1797            | Ronin
1798            | RoninTestnet
1799            | Cfx
1800            | CfxTestnet
1801            | Pulsechain
1802            | PulsechainTestnet
1803            | AutonomysNovaTestnet
1804            | Iotex
1805            | HappychainTestnet
1806            | SonicBlaze
1807            | SonicTestnet
1808            | Treasure
1809            | TreasureTopaz
1810            | BerachainBepolia
1811            | BerachainBartio
1812            | BerachainArtio
1813            | TelosEvm
1814            | TelosEvmTestnet
1815            | Lens
1816            | LensTestnet
1817            | Sei => return None,
1818        };
1819
1820        Some(api_key_name)
1821    }
1822
1823    /// Returns the chain's blockchain explorer's API key, from the environment variable with the
1824    /// name specified in [`etherscan_api_key_name`](NamedChain::etherscan_api_key_name).
1825    ///
1826    /// # Examples
1827    ///
1828    /// ```
1829    /// use alloy_chains::NamedChain;
1830    ///
1831    /// let chain = NamedChain::Mainnet;
1832    /// unsafe {
1833    ///     std::env::set_var(chain.etherscan_api_key_name().unwrap(), "KEY");
1834    /// }
1835    /// assert_eq!(chain.etherscan_api_key().as_deref(), Some("KEY"));
1836    /// ```
1837    #[cfg(feature = "std")]
1838    pub fn etherscan_api_key(self) -> Option<String> {
1839        self.etherscan_api_key_name().and_then(|name| std::env::var(name).ok())
1840    }
1841
1842    /// Returns the address of the public DNS node list for the given chain.
1843    ///
1844    /// See also <https://github.com/ethereum/discv4-dns-lists>.
1845    pub fn public_dns_network_protocol(self) -> Option<String> {
1846        use NamedChain::*;
1847
1848        const DNS_PREFIX: &str = "enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@";
1849        if let Mainnet | Goerli | Sepolia | Ropsten | Rinkeby | Holesky | Hoodi = self {
1850            // `{DNS_PREFIX}all.{self.lower()}.ethdisco.net`
1851            let mut s = String::with_capacity(DNS_PREFIX.len() + 32);
1852            s.push_str(DNS_PREFIX);
1853            s.push_str("all.");
1854            let chain_str = self.as_ref();
1855            s.push_str(chain_str);
1856            let l = s.len();
1857            s[l - chain_str.len()..].make_ascii_lowercase();
1858            s.push_str(".ethdisco.net");
1859
1860            Some(s)
1861        } else {
1862            None
1863        }
1864    }
1865
1866    /// Returns the address of the most popular wrapped native token address for this chain, if it
1867    /// exists.
1868    ///
1869    /// Example:
1870    ///
1871    /// ```
1872    /// use alloy_chains::NamedChain;
1873    /// use alloy_primitives::address;
1874    ///
1875    /// let chain = NamedChain::Mainnet;
1876    /// assert_eq!(
1877    ///     chain.wrapped_native_token(),
1878    ///     Some(address!("C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"))
1879    /// );
1880    /// ```
1881    pub const fn wrapped_native_token(self) -> Option<Address> {
1882        use NamedChain::*;
1883
1884        let addr = match self {
1885            Mainnet => address!("C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
1886            Optimism => address!("4200000000000000000000000000000000000006"),
1887            BinanceSmartChain => address!("bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"),
1888            OpBNBMainnet => address!("4200000000000000000000000000000000000006"),
1889            Arbitrum => address!("82af49447d8a07e3bd95bd0d56f35241523fbab1"),
1890            Base => address!("4200000000000000000000000000000000000006"),
1891            Linea => address!("e5d7c2a44ffddf6b295a15c148167daaaf5cf34f"),
1892            Mantle => address!("deaddeaddeaddeaddeaddeaddeaddeaddead1111"),
1893            Blast => address!("4300000000000000000000000000000000000004"),
1894            Gnosis => address!("e91d153e0b41518a2ce8dd3d7944fa863463a97d"),
1895            Scroll => address!("5300000000000000000000000000000000000004"),
1896            Taiko => address!("a51894664a773981c6c112c43ce576f315d5b1b6"),
1897            Avalanche => address!("b31f66aa3c1e785363f0875a1b74e27b85fd66c7"),
1898            Polygon => address!("0d500b1d8e8ef31e21c99d1db9a6444d3adf1270"),
1899            Fantom => address!("21be370d5312f44cb42ce377bc9b8a0cef1a4c83"),
1900            Iotex => address!("a00744882684c3e4747faefd68d283ea44099d03"),
1901            Core => address!("40375C92d9FAf44d2f9db9Bd9ba41a3317a2404f"),
1902            Merlin => address!("F6D226f9Dc15d9bB51182815b320D3fBE324e1bA"),
1903            Bitlayer => address!("ff204e2681a6fa0e2c3fade68a1b28fb90e4fc5f"),
1904            ApeChain => address!("48b62137EdfA95a428D35C09E44256a739F6B557"),
1905            Vana => address!("00EDdD9621Fb08436d0331c149D1690909a5906d"),
1906            Zeta => address!("5F0b1a82749cb4E2278EC87F8BF6B618dC71a8bf"),
1907            Kaia => address!("19aac5f612f524b754ca7e7c41cbfa2e981a4432"),
1908            Story => address!("1514000000000000000000000000000000000000"),
1909            Treasure => address!("263d8f36bb8d0d9526255e205868c26690b04b88"),
1910            Superposition => address!("1fB719f10b56d7a85DCD32f27f897375fB21cfdd"),
1911            Sonic => address!("039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38"),
1912            Berachain => address!("6969696969696969696969696969696969696969"),
1913            Hyperliquid => address!("5555555555555555555555555555555555555555"),
1914            Abstract => address!("3439153EB7AF838Ad19d56E1571FBD09333C2809"),
1915            Sei => address!("E30feDd158A2e3b13e9badaeABaFc5516e95e8C7"),
1916            ZkSync => address!("5aea5775959fbc2557cc8789bc1bf90a239d9a91"),
1917            Sophon => address!("f1f9e08a0818594fde4713ae0db1e46672ca960e"),
1918            _ => return None,
1919        };
1920
1921        Some(addr)
1922    }
1923}
1924
1925#[cfg(test)]
1926mod tests {
1927    use super::*;
1928    use strum::{EnumCount, IntoEnumIterator};
1929
1930    #[allow(unused_imports)]
1931    use alloc::string::ToString;
1932
1933    #[test]
1934    #[cfg(feature = "serde")]
1935    fn default() {
1936        assert_eq!(serde_json::to_string(&NamedChain::default()).unwrap(), "\"mainnet\"");
1937    }
1938
1939    #[test]
1940    fn enum_iter() {
1941        assert_eq!(NamedChain::COUNT, NamedChain::iter().size_hint().0);
1942    }
1943
1944    #[test]
1945    fn roundtrip_string() {
1946        for chain in NamedChain::iter() {
1947            let chain_string = chain.to_string();
1948            assert_eq!(chain_string, format!("{chain}"));
1949            assert_eq!(chain_string.as_str(), chain.as_ref());
1950            #[cfg(feature = "serde")]
1951            assert_eq!(serde_json::to_string(&chain).unwrap(), format!("\"{chain_string}\""));
1952
1953            assert_eq!(chain_string.parse::<NamedChain>().unwrap(), chain);
1954        }
1955    }
1956
1957    #[test]
1958    #[cfg(feature = "serde")]
1959    fn roundtrip_serde() {
1960        for chain in NamedChain::iter() {
1961            let chain_string = serde_json::to_string(&chain).unwrap();
1962            let chain_string = chain_string.replace('-', "_");
1963            assert_eq!(serde_json::from_str::<'_, NamedChain>(&chain_string).unwrap(), chain);
1964        }
1965    }
1966
1967    #[test]
1968    fn aliases() {
1969        use NamedChain::*;
1970
1971        // kebab-case
1972        const ALIASES: &[(NamedChain, &[&str])] = &[
1973            (Mainnet, &["ethlive"]),
1974            (BinanceSmartChain, &["bsc", "bnb-smart-chain", "binance-smart-chain"]),
1975            (
1976                BinanceSmartChainTestnet,
1977                &["bsc-testnet", "bnb-smart-chain-testnet", "binance-smart-chain-testnet"],
1978            ),
1979            (Gnosis, &["gnosis", "gnosis-chain"]),
1980            (PolygonMumbai, &["mumbai"]),
1981            (PolygonZkEvm, &["zkevm", "polygon-zkevm"]),
1982            (PolygonZkEvmTestnet, &["zkevm-testnet", "polygon-zkevm-testnet"]),
1983            (AnvilHardhat, &["anvil", "hardhat"]),
1984            (AvalancheFuji, &["fuji"]),
1985            (ZkSync, &["zksync"]),
1986            (ZkSyncTestnet, &["zksync-testnet"]),
1987            (Mantle, &["mantle"]),
1988            (MantleTestnet, &["mantle-testnet"]),
1989            (MantleSepolia, &["mantle-sepolia"]),
1990            (GravityAlphaMainnet, &["gravity-alpha-mainnet"]),
1991            (GravityAlphaTestnetSepolia, &["gravity-alpha-testnet-sepolia"]),
1992            (Bob, &["bob"]),
1993            (BobSepolia, &["bob-sepolia"]),
1994            (HappychainTestnet, &["happychain-testnet"]),
1995            (Xai, &["xai"]),
1996            (XaiSepolia, &["xai-sepolia"]),
1997            (Base, &["base"]),
1998            (BaseGoerli, &["base-goerli"]),
1999            (BaseSepolia, &["base-sepolia"]),
2000            (Fraxtal, &["fraxtal"]),
2001            (FraxtalTestnet, &["fraxtal-testnet"]),
2002            (Ink, &["ink"]),
2003            (InkSepolia, &["ink-sepolia"]),
2004            (BlastSepolia, &["blast-sepolia"]),
2005            (Syndr, &["syndr"]),
2006            (SyndrSepolia, &["syndr-sepolia"]),
2007            (LineaGoerli, &["linea-goerli"]),
2008            (LineaSepolia, &["linea-sepolia"]),
2009            (AutonomysNovaTestnet, &["autonomys-nova-testnet"]),
2010            (Immutable, &["immutable"]),
2011            (ImmutableTestnet, &["immutable-testnet"]),
2012            (Soneium, &["soneium"]),
2013            (SoneiumMinatoTestnet, &["soneium-minato-testnet"]),
2014            (ApeChain, &["apechain"]),
2015            (Curtis, &["apechain-testnet", "curtis"]),
2016            (Treasure, &["treasure"]),
2017            (TreasureTopaz, &["treasure-topaz-testnet", "treasure-topaz"]),
2018            (BerachainBepolia, &["berachain-bepolia-testnet", "berachain-bepolia"]),
2019            (BerachainArtio, &["berachain-artio-testnet", "berachain-artio"]),
2020            (BerachainBartio, &["berachain-bartio-testnet", "berachain-bartio"]),
2021            (SuperpositionTestnet, &["superposition-testnet"]),
2022            (Superposition, &["superposition"]),
2023            (Hyperliquid, &["hyperliquid"]),
2024            (Abstract, &["abstract"]),
2025            (AbstractTestnet, &["abstract-testnet"]),
2026            (Sophon, &["sophon"]),
2027            (SophonTestnet, &["sophon-testnet"]),
2028            (Lens, &["lens"]),
2029            (LensTestnet, &["lens-testnet"]),
2030        ];
2031
2032        for &(chain, aliases) in ALIASES {
2033            for &alias in aliases {
2034                let named = alias.parse::<NamedChain>().expect(alias);
2035                assert_eq!(named, chain);
2036
2037                #[cfg(feature = "serde")]
2038                {
2039                    assert_eq!(
2040                        serde_json::from_str::<NamedChain>(&format!("\"{alias}\"")).unwrap(),
2041                        chain
2042                    );
2043
2044                    assert_eq!(
2045                        serde_json::from_str::<NamedChain>(&format!("\"{named}\"")).unwrap(),
2046                        chain
2047                    );
2048                }
2049            }
2050        }
2051    }
2052
2053    #[test]
2054    #[cfg(feature = "serde")]
2055    fn serde_to_string_match() {
2056        for chain in NamedChain::iter() {
2057            let chain_serde = serde_json::to_string(&chain).unwrap();
2058            let chain_string = format!("\"{chain}\"");
2059            assert_eq!(chain_serde, chain_string);
2060        }
2061    }
2062
2063    #[test]
2064    fn test_dns_network() {
2065        let s = "enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@all.mainnet.ethdisco.net";
2066        assert_eq!(NamedChain::Mainnet.public_dns_network_protocol().unwrap(), s);
2067    }
2068
2069    #[test]
2070    fn ensure_no_trailing_etherscan_url_separator() {
2071        for chain in NamedChain::iter() {
2072            if let Some((api, base)) = chain.etherscan_urls() {
2073                assert!(!api.ends_with('/'), "{chain:?} api url has trailing /");
2074                assert!(!base.ends_with('/'), "{chain:?} base url has trailing /");
2075            }
2076        }
2077    }
2078}