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