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