-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathchains.ts
More file actions
358 lines (340 loc) · 8.96 KB
/
Copy pathchains.ts
File metadata and controls
358 lines (340 loc) · 8.96 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
import { type Chain } 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';
// 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,
// 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,
};
// 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,
// 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,
};
// 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',
// 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',
};
/**
* 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') {
if (!chainMap[chainIdentifier]) {
throw new Error(`Unsupported chain ID: ${chainIdentifier}. Use a supported network.`);
}
return chainIdentifier;
}
const networkName = chainIdentifier.toLowerCase();
const chainId = networkNameMap[networkName];
if (chainId !== undefined) {
return chainId;
}
const parsedId = parseInt(networkName);
if (!isNaN(parsedId) && chainMap[parsedId]) {
return parsedId;
}
throw new Error(`Unknown network: "${chainIdentifier}". Supported: ${getSupportedNetworks().slice(0, 10).join(', ')}...`);
}
/**
* 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();
if (networkNameMap[networkName]) {
const chain = chainMap[networkNameMap[networkName]];
if (!chain) throw new Error(`Chain config missing for network: ${chainIdentifier}`);
return chain;
}
throw new Error(`Unsupported network: ${chainIdentifier}`);
}
const chain = chainMap[chainIdentifier];
if (!chain) {
throw new Error(`Unsupported chain ID: ${chainIdentifier}`);
}
return chain;
}
/**
* 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();
}