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