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