-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathchains.ts
More file actions
409 lines (388 loc) · 9.9 KB
/
Copy pathchains.ts
File metadata and controls
409 lines (388 loc) · 9.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
import { type Chain, defineChain } from 'viem';
import {
// Mainnets
mainnet,
optimism,
arbitrum,
arbitrumNova,
base,
polygon,
polygonZkEvm,
avalanche,
bsc,
zksync,
linea,
celo,
gnosis,
fantom,
filecoin,
moonbeam,
moonriver,
cronos,
lumiaMainnet,
scroll,
mantle,
manta,
blast,
fraxtal,
mode,
metis,
kroma,
zora,
aurora,
canto,
flowMainnet,
// Testnets
sepolia,
optimismSepolia,
arbitrumSepolia,
baseSepolia,
polygonAmoy,
avalancheFuji,
bscTestnet,
zksyncSepoliaTestnet,
lineaSepolia,
lumiaTestnet,
scrollSepolia,
mantleSepoliaTestnet,
mantaSepoliaTestnet,
blastSepolia,
fraxtalTestnet,
modeTestnet,
metisSepolia,
kromaSepolia,
zoraSepolia,
celoAlfajores,
goerli,
holesky,
flowTestnet,
filecoinCalibration
} from 'viem/chains';
// Plasma (XPL) - not yet exported by viem/chains as of viem 2.39.3.
// Mainnet (id 9745) and testnet (id 9746) per chainid.network / ethereum-lists.
export const plasma = defineChain({
id: 9745,
name: 'Plasma',
nativeCurrency: {
name: 'Plasma',
symbol: 'XPL',
decimals: 18,
},
rpcUrls: {
default: {
http: ['https://rpc.plasma.to'],
},
},
blockExplorers: {
default: {
name: 'Plasma Explorer',
url: 'https://plasmascan.to',
},
},
});
export const plasmaTestnet = defineChain({
id: 9746,
name: 'Plasma Testnet',
nativeCurrency: {
name: 'Testnet Plasma',
symbol: 'XPL',
decimals: 18,
},
rpcUrls: {
default: {
http: ['https://testnet-rpc.plasma.to'],
},
},
blockExplorers: {
default: {
name: 'Plasma Testnet Explorer',
url: 'https://testnet.plasmascan.to',
},
},
testnet: true,
});
// Default configuration values
export const DEFAULT_RPC_URL = 'https://eth.llamarpc.com';
export const DEFAULT_CHAIN_ID = 1;
// Map chain IDs to chains
export const chainMap: Record<number, Chain> = {
// Mainnets
1: mainnet,
10: optimism,
42161: arbitrum,
42170: arbitrumNova,
8453: base,
137: polygon,
1101: polygonZkEvm,
43114: avalanche,
56: bsc,
324: zksync,
59144: linea,
42220: celo,
100: gnosis,
250: fantom,
314: filecoin,
1284: moonbeam,
1285: moonriver,
25: cronos,
534352: scroll,
5000: mantle,
169: manta,
994873017: lumiaMainnet,
81457: blast,
252: fraxtal,
34443: mode,
1088: metis,
255: kroma,
7777777: zora,
1313161554: aurora,
7700: canto,
747: flowMainnet,
9745: plasma,
// Testnets
11155111: sepolia,
11155420: optimismSepolia,
421614: arbitrumSepolia,
84532: baseSepolia,
80002: polygonAmoy,
43113: avalancheFuji,
97: bscTestnet,
300: zksyncSepoliaTestnet,
59141: lineaSepolia,
1952959480: lumiaTestnet,
534351: scrollSepolia,
5003: mantleSepoliaTestnet,
3441006: mantaSepoliaTestnet,
168587773: blastSepolia,
2522: fraxtalTestnet,
919: modeTestnet,
59902: metisSepolia,
2358: kromaSepolia,
999999999: zoraSepolia,
44787: celoAlfajores,
5: goerli,
17000: holesky,
545: flowTestnet,
314159: filecoinCalibration,
9746: plasmaTestnet,
};
// Map network names to chain IDs for easier reference
export const networkNameMap: Record<string, number> = {
// Mainnets
'ethereum': 1,
'mainnet': 1,
'eth': 1,
'optimism': 10,
'op': 10,
'arbitrum': 42161,
'arb': 42161,
'arbitrum-nova': 42170,
'arbitrumnova': 42170,
'base': 8453,
'polygon': 137,
'matic': 137,
'polygon-zkevm': 1101,
'polygonzkevm': 1101,
'avalanche': 43114,
'avax': 43114,
'binance': 56,
'bsc': 56,
'zksync': 324,
'linea': 59144,
'celo': 42220,
'gnosis': 100,
'xdai': 100,
'fantom': 250,
'ftm': 250,
'filecoin': 314,
'fil': 314,
'moonbeam': 1284,
'moonriver': 1285,
'cronos': 25,
'scroll': 534352,
'mantle': 5000,
'manta': 169,
'lumia': 994873017,
'blast': 81457,
'fraxtal': 252,
'mode': 34443,
'metis': 1088,
'kroma': 255,
'zora': 7777777,
'aurora': 1313161554,
'canto': 7700,
'flow': 747,
'plasma': 9745,
// Testnets
'sepolia': 11155111,
'optimism-sepolia': 11155420,
'optimismsepolia': 11155420,
'arbitrum-sepolia': 421614,
'arbitrumsepolia': 421614,
'base-sepolia': 84532,
'basesepolia': 84532,
'polygon-amoy': 80002,
'polygonamoy': 80002,
'avalanche-fuji': 43113,
'avalanchefuji': 43113,
'fuji': 43113,
'bsc-testnet': 97,
'bsctestnet': 97,
'zksync-sepolia': 300,
'zksyncsepolia': 300,
'linea-sepolia': 59141,
'lineasepolia': 59141,
'lumia-testnet': 1952959480,
'scroll-sepolia': 534351,
'scrollsepolia': 534351,
'mantle-sepolia': 5003,
'mantlesepolia': 5003,
'manta-sepolia': 3441006,
'mantasepolia': 3441006,
'blast-sepolia': 168587773,
'blastsepolia': 168587773,
'fraxtal-testnet': 2522,
'fraxtaltestnet': 2522,
'mode-testnet': 919,
'modetestnet': 919,
'metis-sepolia': 59902,
'metissepolia': 59902,
'kroma-sepolia': 2358,
'kromasepolia': 2358,
'zora-sepolia': 999999999,
'zorasepolia': 999999999,
'celo-alfajores': 44787,
'celoalfajores': 44787,
'alfajores': 44787,
'goerli': 5,
'holesky': 17000,
'flow-testnet': 545,
'filecoin-calibration': 314159,
'plasma-testnet': 9746,
'plasmatestnet': 9746,
};
// Map chain IDs to RPC URLs
export const rpcUrlMap: Record<number, string> = {
// Mainnets
1: 'https://eth.llamarpc.com',
10: 'https://mainnet.optimism.io',
42161: 'https://arb1.arbitrum.io/rpc',
42170: 'https://nova.arbitrum.io/rpc',
8453: 'https://mainnet.base.org',
137: 'https://polygon-rpc.com',
1101: 'https://zkevm-rpc.com',
43114: 'https://api.avax.network/ext/bc/C/rpc',
56: 'https://bsc-dataseed.binance.org',
324: 'https://mainnet.era.zksync.io',
59144: 'https://rpc.linea.build',
42220: 'https://forno.celo.org',
100: 'https://rpc.gnosischain.com',
250: 'https://rpc.ftm.tools',
314: 'https://api.node.glif.io/rpc/v1',
1284: 'https://rpc.api.moonbeam.network',
1285: 'https://rpc.api.moonriver.moonbeam.network',
25: 'https://evm.cronos.org',
534352: 'https://rpc.scroll.io',
5000: 'https://rpc.mantle.xyz',
169: 'https://pacific-rpc.manta.network/http',
81457: 'https://rpc.blast.io',
252: 'https://rpc.frax.com',
994873017: 'https://mainnet-rpc.lumia.org',
34443: 'https://mainnet.mode.network',
1088: 'https://andromeda.metis.io/?owner=1088',
255: 'https://api.kroma.network',
7777777: 'https://rpc.zora.energy',
1313161554: 'https://mainnet.aurora.dev',
7700: 'https://canto.gravitychain.io',
747: 'https://mainnet.evm.nodes.onflow.org',
9745: 'https://rpc.plasma.to',
// Testnets
11155111: 'https://sepolia.drpc.org',
11155420: 'https://sepolia.optimism.io',
421614: 'https://sepolia-rpc.arbitrum.io/rpc',
84532: 'https://sepolia.base.org',
80002: 'https://rpc-amoy.polygon.technology',
43113: 'https://api.avax-test.network/ext/bc/C/rpc',
97: 'https://data-seed-prebsc-1-s1.binance.org:8545',
300: 'https://sepolia.era.zksync.dev',
59141: 'https://rpc.sepolia.linea.build',
534351: 'https://sepolia-rpc.scroll.io',
5003: 'https://rpc.sepolia.mantle.xyz',
3441006: 'https://pacific-rpc.sepolia.manta.network/http',
1952959480: 'https://testnet-rpc.lumia.org',
168587773: 'https://sepolia.blast.io',
2522: 'https://rpc.testnet.frax.com',
919: 'https://sepolia.mode.network',
59902: 'https://sepolia.metis.io/?owner=59902',
2358: 'https://api.sepolia.kroma.network',
999999999: 'https://sepolia.rpc.zora.energy',
44787: 'https://alfajores-forno.celo-testnet.org',
5: 'https://rpc.ankr.com/eth_goerli',
17000: 'https://ethereum-holesky.publicnode.com',
545: 'https://testnet.evm.nodes.onflow.org',
314159: 'https://api.calibration.node.glif.io/rpc/v1',
9746: 'https://testnet-rpc.plasma.to',
};
/**
* Resolves a chain identifier (number or string) to a chain ID
* @param chainIdentifier Chain ID (number) or network name (string)
* @returns The resolved chain ID
*/
export function resolveChainId(chainIdentifier: number | string): number {
if (typeof chainIdentifier === 'number') {
return chainIdentifier;
}
// Convert to lowercase for case-insensitive matching
const networkName = chainIdentifier.toLowerCase();
// Check if the network name is in our map
const chainId = networkNameMap[networkName];
if (chainId !== undefined) {
return chainId;
}
// Try parsing as a number
const parsedId = parseInt(networkName);
if (!isNaN(parsedId)) {
return parsedId;
}
// Default to mainnet if not found
return DEFAULT_CHAIN_ID;
}
/**
* Returns the chain configuration for the specified chain ID or network name
* @param chainIdentifier Chain ID (number) or network name (string)
* @returns The chain configuration
* @throws Error if the network is not supported (when string is provided)
*/
export function getChain(chainIdentifier: number | string = DEFAULT_CHAIN_ID): Chain {
if (typeof chainIdentifier === 'string') {
const networkName = chainIdentifier.toLowerCase();
// Try to get from direct network name mapping first
if (networkNameMap[networkName]) {
return chainMap[networkNameMap[networkName]] || mainnet;
}
// If not found, throw an error
throw new Error(`Unsupported network: ${chainIdentifier}`);
}
// If it's a number, return the chain from chainMap
return chainMap[chainIdentifier] || mainnet;
}
/**
* Gets the appropriate RPC URL for the specified chain ID or network name
* @param chainIdentifier Chain ID (number) or network name (string)
* @returns The RPC URL for the specified chain
*/
export function getRpcUrl(chainIdentifier: number | string = DEFAULT_CHAIN_ID): string {
const chainId = typeof chainIdentifier === 'string'
? resolveChainId(chainIdentifier)
: chainIdentifier;
return rpcUrlMap[chainId] || DEFAULT_RPC_URL;
}
/**
* Get a list of supported networks
* @returns Array of supported network names (excluding short aliases)
*/
export function getSupportedNetworks(): string[] {
return Object.keys(networkNameMap)
.filter(name => name.length > 2) // Filter out short aliases
.sort();
}