@codkit/config 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +70 -2
- package/dist/chunk-N3OT5BNF.cjs +655 -0
- package/dist/chunk-N3OT5BNF.cjs.map +1 -0
- package/dist/chunk-ZRZNU5KJ.js +655 -0
- package/dist/chunk-ZRZNU5KJ.js.map +1 -0
- package/dist/index.cjs +76 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +41 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +76 -0
- package/dist/index.js.map +1 -0
- package/dist/rpc-DaYsu4c7.d.cts +669 -0
- package/dist/rpc-DaYsu4c7.d.ts +669 -0
- package/dist/viem.cjs +30 -0
- package/dist/viem.cjs.map +1 -0
- package/dist/viem.d.cts +20 -0
- package/dist/viem.d.ts +20 -0
- package/dist/viem.js +30 -0
- package/dist/viem.js.map +1 -0
- package/package.json +73 -4
- package/src/chains.ts +160 -0
- package/src/env.ts +59 -0
- package/src/evm-chains.ts +438 -0
- package/src/explorer.ts +13 -0
- package/src/index.ts +5 -0
- package/src/rpc.ts +111 -0
- package/src/types.ts +42 -0
- package/src/viem.ts +33 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
// Generated by scripts/gen-evm.mjs from viem 2.58.0. Do not edit by hand.
|
|
2
|
+
import type { ChainConfig } from "./types.js";
|
|
3
|
+
|
|
4
|
+
export const evmChains = [
|
|
5
|
+
{
|
|
6
|
+
key: "ethereum",
|
|
7
|
+
id: "eip155:1",
|
|
8
|
+
ecosystem: "evm",
|
|
9
|
+
name: "Ethereum",
|
|
10
|
+
testnet: false,
|
|
11
|
+
chainId: 1,
|
|
12
|
+
nativeCurrency: {
|
|
13
|
+
name: "Ether",
|
|
14
|
+
symbol: "ETH",
|
|
15
|
+
decimals: 18,
|
|
16
|
+
},
|
|
17
|
+
rpcUrls: ["https://ethereum.reth.rs/rpc"],
|
|
18
|
+
explorer: {
|
|
19
|
+
name: "Etherscan",
|
|
20
|
+
url: "https://etherscan.io",
|
|
21
|
+
},
|
|
22
|
+
providers: {
|
|
23
|
+
alchemy: "eth-mainnet",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
key: "sepolia",
|
|
28
|
+
id: "eip155:11155111",
|
|
29
|
+
ecosystem: "evm",
|
|
30
|
+
name: "Sepolia",
|
|
31
|
+
testnet: true,
|
|
32
|
+
chainId: 11155111,
|
|
33
|
+
nativeCurrency: {
|
|
34
|
+
name: "Sepolia Ether",
|
|
35
|
+
symbol: "ETH",
|
|
36
|
+
decimals: 18,
|
|
37
|
+
},
|
|
38
|
+
rpcUrls: ["https://11155111.rpc.thirdweb.com"],
|
|
39
|
+
explorer: {
|
|
40
|
+
name: "Etherscan",
|
|
41
|
+
url: "https://sepolia.etherscan.io",
|
|
42
|
+
},
|
|
43
|
+
providers: {
|
|
44
|
+
alchemy: "eth-sepolia",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
key: "base",
|
|
49
|
+
id: "eip155:8453",
|
|
50
|
+
ecosystem: "evm",
|
|
51
|
+
name: "Base",
|
|
52
|
+
testnet: false,
|
|
53
|
+
chainId: 8453,
|
|
54
|
+
nativeCurrency: {
|
|
55
|
+
name: "Ether",
|
|
56
|
+
symbol: "ETH",
|
|
57
|
+
decimals: 18,
|
|
58
|
+
},
|
|
59
|
+
rpcUrls: ["https://mainnet.base.org"],
|
|
60
|
+
explorer: {
|
|
61
|
+
name: "Basescan",
|
|
62
|
+
url: "https://basescan.org",
|
|
63
|
+
},
|
|
64
|
+
providers: {
|
|
65
|
+
alchemy: "base-mainnet",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
key: "base-sepolia",
|
|
70
|
+
id: "eip155:84532",
|
|
71
|
+
ecosystem: "evm",
|
|
72
|
+
name: "Base Sepolia",
|
|
73
|
+
testnet: true,
|
|
74
|
+
chainId: 84532,
|
|
75
|
+
nativeCurrency: {
|
|
76
|
+
name: "Sepolia Ether",
|
|
77
|
+
symbol: "ETH",
|
|
78
|
+
decimals: 18,
|
|
79
|
+
},
|
|
80
|
+
rpcUrls: ["https://sepolia.base.org"],
|
|
81
|
+
explorer: {
|
|
82
|
+
name: "Basescan",
|
|
83
|
+
url: "https://sepolia.basescan.org",
|
|
84
|
+
},
|
|
85
|
+
providers: {
|
|
86
|
+
alchemy: "base-sepolia",
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
key: "optimism",
|
|
91
|
+
id: "eip155:10",
|
|
92
|
+
ecosystem: "evm",
|
|
93
|
+
name: "OP Mainnet",
|
|
94
|
+
testnet: false,
|
|
95
|
+
chainId: 10,
|
|
96
|
+
nativeCurrency: {
|
|
97
|
+
name: "Ether",
|
|
98
|
+
symbol: "ETH",
|
|
99
|
+
decimals: 18,
|
|
100
|
+
},
|
|
101
|
+
rpcUrls: ["https://mainnet.optimism.io"],
|
|
102
|
+
explorer: {
|
|
103
|
+
name: "Optimism Explorer",
|
|
104
|
+
url: "https://optimistic.etherscan.io",
|
|
105
|
+
},
|
|
106
|
+
providers: {
|
|
107
|
+
alchemy: "opt-mainnet",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
key: "optimism-sepolia",
|
|
112
|
+
id: "eip155:11155420",
|
|
113
|
+
ecosystem: "evm",
|
|
114
|
+
name: "OP Sepolia",
|
|
115
|
+
testnet: true,
|
|
116
|
+
chainId: 11155420,
|
|
117
|
+
nativeCurrency: {
|
|
118
|
+
name: "Sepolia Ether",
|
|
119
|
+
symbol: "ETH",
|
|
120
|
+
decimals: 18,
|
|
121
|
+
},
|
|
122
|
+
rpcUrls: ["https://sepolia.optimism.io"],
|
|
123
|
+
explorer: {
|
|
124
|
+
name: "Blockscout",
|
|
125
|
+
url: "https://optimism-sepolia.blockscout.com",
|
|
126
|
+
},
|
|
127
|
+
providers: {
|
|
128
|
+
alchemy: "opt-sepolia",
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
key: "arbitrum",
|
|
133
|
+
id: "eip155:42161",
|
|
134
|
+
ecosystem: "evm",
|
|
135
|
+
name: "Arbitrum One",
|
|
136
|
+
testnet: false,
|
|
137
|
+
chainId: 42161,
|
|
138
|
+
nativeCurrency: {
|
|
139
|
+
name: "Ether",
|
|
140
|
+
symbol: "ETH",
|
|
141
|
+
decimals: 18,
|
|
142
|
+
},
|
|
143
|
+
rpcUrls: ["https://arb1.arbitrum.io/rpc"],
|
|
144
|
+
explorer: {
|
|
145
|
+
name: "Arbiscan",
|
|
146
|
+
url: "https://arbiscan.io",
|
|
147
|
+
},
|
|
148
|
+
providers: {
|
|
149
|
+
alchemy: "arb-mainnet",
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
key: "arbitrum-sepolia",
|
|
154
|
+
id: "eip155:421614",
|
|
155
|
+
ecosystem: "evm",
|
|
156
|
+
name: "Arbitrum Sepolia",
|
|
157
|
+
testnet: true,
|
|
158
|
+
chainId: 421614,
|
|
159
|
+
nativeCurrency: {
|
|
160
|
+
name: "Arbitrum Sepolia Ether",
|
|
161
|
+
symbol: "ETH",
|
|
162
|
+
decimals: 18,
|
|
163
|
+
},
|
|
164
|
+
rpcUrls: ["https://sepolia-rollup.arbitrum.io/rpc"],
|
|
165
|
+
explorer: {
|
|
166
|
+
name: "Arbiscan",
|
|
167
|
+
url: "https://sepolia.arbiscan.io",
|
|
168
|
+
},
|
|
169
|
+
providers: {
|
|
170
|
+
alchemy: "arb-sepolia",
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
key: "polygon",
|
|
175
|
+
id: "eip155:137",
|
|
176
|
+
ecosystem: "evm",
|
|
177
|
+
name: "Polygon",
|
|
178
|
+
testnet: false,
|
|
179
|
+
chainId: 137,
|
|
180
|
+
nativeCurrency: {
|
|
181
|
+
name: "POL",
|
|
182
|
+
symbol: "POL",
|
|
183
|
+
decimals: 18,
|
|
184
|
+
},
|
|
185
|
+
rpcUrls: ["https://polygon.drpc.org"],
|
|
186
|
+
explorer: {
|
|
187
|
+
name: "PolygonScan",
|
|
188
|
+
url: "https://polygonscan.com",
|
|
189
|
+
},
|
|
190
|
+
providers: {
|
|
191
|
+
alchemy: "polygon-mainnet",
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
key: "polygon-amoy",
|
|
196
|
+
id: "eip155:80002",
|
|
197
|
+
ecosystem: "evm",
|
|
198
|
+
name: "Polygon Amoy",
|
|
199
|
+
testnet: true,
|
|
200
|
+
chainId: 80002,
|
|
201
|
+
nativeCurrency: {
|
|
202
|
+
name: "POL",
|
|
203
|
+
symbol: "POL",
|
|
204
|
+
decimals: 18,
|
|
205
|
+
},
|
|
206
|
+
rpcUrls: ["https://polygon-amoy.drpc.org"],
|
|
207
|
+
explorer: {
|
|
208
|
+
name: "PolygonScan",
|
|
209
|
+
url: "https://amoy.polygonscan.com",
|
|
210
|
+
},
|
|
211
|
+
providers: {
|
|
212
|
+
alchemy: "polygon-amoy",
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
key: "bsc",
|
|
217
|
+
id: "eip155:56",
|
|
218
|
+
ecosystem: "evm",
|
|
219
|
+
name: "BNB Smart Chain",
|
|
220
|
+
testnet: false,
|
|
221
|
+
chainId: 56,
|
|
222
|
+
nativeCurrency: {
|
|
223
|
+
decimals: 18,
|
|
224
|
+
name: "BNB",
|
|
225
|
+
symbol: "BNB",
|
|
226
|
+
},
|
|
227
|
+
rpcUrls: ["https://56.rpc.thirdweb.com"],
|
|
228
|
+
explorer: {
|
|
229
|
+
name: "BscScan",
|
|
230
|
+
url: "https://bscscan.com",
|
|
231
|
+
},
|
|
232
|
+
providers: {
|
|
233
|
+
alchemy: "bnb-mainnet",
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
key: "bsc-testnet",
|
|
238
|
+
id: "eip155:97",
|
|
239
|
+
ecosystem: "evm",
|
|
240
|
+
name: "BNB Smart Chain Testnet",
|
|
241
|
+
testnet: true,
|
|
242
|
+
chainId: 97,
|
|
243
|
+
nativeCurrency: {
|
|
244
|
+
decimals: 18,
|
|
245
|
+
name: "BNB",
|
|
246
|
+
symbol: "tBNB",
|
|
247
|
+
},
|
|
248
|
+
rpcUrls: ["https://data-seed-prebsc-1-s1.bnbchain.org:8545"],
|
|
249
|
+
explorer: {
|
|
250
|
+
name: "BscScan",
|
|
251
|
+
url: "https://testnet.bscscan.com",
|
|
252
|
+
},
|
|
253
|
+
providers: {
|
|
254
|
+
alchemy: "bnb-testnet",
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
key: "avalanche",
|
|
259
|
+
id: "eip155:43114",
|
|
260
|
+
ecosystem: "evm",
|
|
261
|
+
name: "Avalanche",
|
|
262
|
+
testnet: false,
|
|
263
|
+
chainId: 43114,
|
|
264
|
+
nativeCurrency: {
|
|
265
|
+
decimals: 18,
|
|
266
|
+
name: "Avalanche",
|
|
267
|
+
symbol: "AVAX",
|
|
268
|
+
},
|
|
269
|
+
rpcUrls: ["https://api.avax.network/ext/bc/C/rpc"],
|
|
270
|
+
explorer: {
|
|
271
|
+
name: "SnowTrace",
|
|
272
|
+
url: "https://snowtrace.io",
|
|
273
|
+
},
|
|
274
|
+
providers: {
|
|
275
|
+
alchemy: "avax-mainnet",
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
key: "avalanche-fuji",
|
|
280
|
+
id: "eip155:43113",
|
|
281
|
+
ecosystem: "evm",
|
|
282
|
+
name: "Avalanche Fuji",
|
|
283
|
+
testnet: true,
|
|
284
|
+
chainId: 43113,
|
|
285
|
+
nativeCurrency: {
|
|
286
|
+
decimals: 18,
|
|
287
|
+
name: "Avalanche Fuji",
|
|
288
|
+
symbol: "AVAX",
|
|
289
|
+
},
|
|
290
|
+
rpcUrls: ["https://api.avax-test.network/ext/bc/C/rpc"],
|
|
291
|
+
explorer: {
|
|
292
|
+
name: "SnowTrace",
|
|
293
|
+
url: "https://testnet.snowtrace.io",
|
|
294
|
+
},
|
|
295
|
+
providers: {
|
|
296
|
+
alchemy: "avax-fuji",
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
key: "celo",
|
|
301
|
+
id: "eip155:42220",
|
|
302
|
+
ecosystem: "evm",
|
|
303
|
+
name: "Celo",
|
|
304
|
+
testnet: false,
|
|
305
|
+
chainId: 42220,
|
|
306
|
+
nativeCurrency: {
|
|
307
|
+
decimals: 18,
|
|
308
|
+
name: "CELO",
|
|
309
|
+
symbol: "CELO",
|
|
310
|
+
},
|
|
311
|
+
rpcUrls: ["https://forno.celo.org"],
|
|
312
|
+
explorer: {
|
|
313
|
+
name: "Celo Explorer",
|
|
314
|
+
url: "https://celoscan.io",
|
|
315
|
+
},
|
|
316
|
+
providers: {
|
|
317
|
+
alchemy: "celo-mainnet",
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
key: "celo-alfajores",
|
|
322
|
+
id: "eip155:44787",
|
|
323
|
+
ecosystem: "evm",
|
|
324
|
+
name: "Alfajores",
|
|
325
|
+
testnet: true,
|
|
326
|
+
chainId: 44787,
|
|
327
|
+
nativeCurrency: {
|
|
328
|
+
decimals: 18,
|
|
329
|
+
name: "CELO",
|
|
330
|
+
symbol: "A-CELO",
|
|
331
|
+
},
|
|
332
|
+
rpcUrls: ["https://alfajores-forno.celo-testnet.org"],
|
|
333
|
+
explorer: {
|
|
334
|
+
name: "Celo Alfajores Explorer",
|
|
335
|
+
url: "https://celo-alfajores.blockscout.com",
|
|
336
|
+
},
|
|
337
|
+
providers: {
|
|
338
|
+
alchemy: "celo-alfajores",
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
key: "linea-sepolia",
|
|
343
|
+
id: "eip155:59141",
|
|
344
|
+
ecosystem: "evm",
|
|
345
|
+
name: "Linea Sepolia Testnet",
|
|
346
|
+
testnet: true,
|
|
347
|
+
chainId: 59141,
|
|
348
|
+
nativeCurrency: {
|
|
349
|
+
name: "Linea Ether",
|
|
350
|
+
symbol: "ETH",
|
|
351
|
+
decimals: 18,
|
|
352
|
+
},
|
|
353
|
+
rpcUrls: ["https://rpc.sepolia.linea.build"],
|
|
354
|
+
wsUrls: ["wss://rpc.sepolia.linea.build"],
|
|
355
|
+
explorer: {
|
|
356
|
+
name: "Etherscan",
|
|
357
|
+
url: "https://sepolia.lineascan.build",
|
|
358
|
+
},
|
|
359
|
+
providers: {
|
|
360
|
+
alchemy: "linea-sepolia",
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
key: "scroll-sepolia",
|
|
365
|
+
id: "eip155:534351",
|
|
366
|
+
ecosystem: "evm",
|
|
367
|
+
name: "Scroll Sepolia",
|
|
368
|
+
testnet: true,
|
|
369
|
+
chainId: 534351,
|
|
370
|
+
nativeCurrency: {
|
|
371
|
+
name: "Ether",
|
|
372
|
+
symbol: "ETH",
|
|
373
|
+
decimals: 18,
|
|
374
|
+
},
|
|
375
|
+
rpcUrls: ["https://sepolia-rpc.scroll.io"],
|
|
376
|
+
explorer: {
|
|
377
|
+
name: "Scrollscan",
|
|
378
|
+
url: "https://sepolia.scrollscan.com",
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
key: "unichain-sepolia",
|
|
383
|
+
id: "eip155:1301",
|
|
384
|
+
ecosystem: "evm",
|
|
385
|
+
name: "Unichain Sepolia",
|
|
386
|
+
testnet: true,
|
|
387
|
+
chainId: 1301,
|
|
388
|
+
nativeCurrency: {
|
|
389
|
+
name: "Ether",
|
|
390
|
+
symbol: "ETH",
|
|
391
|
+
decimals: 18,
|
|
392
|
+
},
|
|
393
|
+
rpcUrls: ["https://sepolia.unichain.org"],
|
|
394
|
+
explorer: {
|
|
395
|
+
name: "Uniscan",
|
|
396
|
+
url: "https://sepolia.uniscan.xyz",
|
|
397
|
+
},
|
|
398
|
+
providers: {
|
|
399
|
+
alchemy: "unichain-sepolia",
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
key: "monad-testnet",
|
|
404
|
+
id: "eip155:10143",
|
|
405
|
+
ecosystem: "evm",
|
|
406
|
+
name: "Monad Testnet",
|
|
407
|
+
testnet: true,
|
|
408
|
+
chainId: 10143,
|
|
409
|
+
nativeCurrency: {
|
|
410
|
+
name: "Testnet MON Token",
|
|
411
|
+
symbol: "MON",
|
|
412
|
+
decimals: 18,
|
|
413
|
+
},
|
|
414
|
+
rpcUrls: ["https://testnet-rpc.monad.xyz"],
|
|
415
|
+
explorer: {
|
|
416
|
+
name: "Monad Testnet explorer",
|
|
417
|
+
url: "https://testnet.monadexplorer.com",
|
|
418
|
+
},
|
|
419
|
+
providers: {
|
|
420
|
+
alchemy: "monad-testnet",
|
|
421
|
+
},
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
key: "anvil",
|
|
425
|
+
id: "eip155:31337",
|
|
426
|
+
ecosystem: "evm",
|
|
427
|
+
name: "Anvil",
|
|
428
|
+
testnet: true,
|
|
429
|
+
chainId: 31337,
|
|
430
|
+
nativeCurrency: {
|
|
431
|
+
decimals: 18,
|
|
432
|
+
name: "Ether",
|
|
433
|
+
symbol: "ETH",
|
|
434
|
+
},
|
|
435
|
+
rpcUrls: ["http://127.0.0.1:8545"],
|
|
436
|
+
wsUrls: ["ws://127.0.0.1:8545"],
|
|
437
|
+
},
|
|
438
|
+
] as const satisfies readonly ChainConfig[];
|
package/src/explorer.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ChainRef, getChain } from "./chains.js";
|
|
2
|
+
|
|
3
|
+
/** Explorer link for a transaction (EVM hash, Solana signature, Sui digest), or undefined if the chain has no explorer. */
|
|
4
|
+
export function explorerTxUrl(chain: ChainRef, hash: string): string | undefined {
|
|
5
|
+
const e = getChain(chain).explorer;
|
|
6
|
+
return e && e.url + (e.tx ?? "/tx/{hash}").replace("{hash}", encodeURIComponent(hash));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Explorer link for an account / address. */
|
|
10
|
+
export function explorerAddressUrl(chain: ChainRef, address: string): string | undefined {
|
|
11
|
+
const e = getChain(chain).explorer;
|
|
12
|
+
return e && e.url + (e.address ?? "/address/{address}").replace("{address}", encodeURIComponent(address));
|
|
13
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { type ChainKey, type ChainRef, chains, defineChain, findChain, getChain, listChains } from "./chains.js";
|
|
2
|
+
export { EnvError, parseEnv, type RpcEnvOptions, rpcEnvSchema } from "./env.js";
|
|
3
|
+
export { explorerAddressUrl, explorerTxUrl } from "./explorer.js";
|
|
4
|
+
export { type Env, envStem, getRpcUrl, getRpcUrls, getWsUrls, type RpcOptions, type RpcProvider, readEnv, redactRpcUrl } from "./rpc.js";
|
|
5
|
+
export type { ChainConfig, Ecosystem, NativeCurrency } from "./types.js";
|
package/src/rpc.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { type ChainRef, getChain } from "./chains.js";
|
|
2
|
+
import type { ChainConfig } from "./types.js";
|
|
3
|
+
|
|
4
|
+
export type Env = Record<string, string | undefined>;
|
|
5
|
+
export type RpcProvider = "alchemy" | "helius";
|
|
6
|
+
|
|
7
|
+
export interface RpcOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Where to read variables. Default: `process.env` when it exists. In browsers pass your
|
|
10
|
+
* public env explicitly (Vite: `import.meta.env`; Next.js: an object of `process.env.NEXT_PUBLIC_…`).
|
|
11
|
+
*/
|
|
12
|
+
env?: Env;
|
|
13
|
+
/** Keyed providers to try, in order. Default: Helius then Alchemy on Solana; Alchemy elsewhere. */
|
|
14
|
+
providers?: RpcProvider[];
|
|
15
|
+
/** Append the chain's public endpoints as the last fallbacks. Default true. */
|
|
16
|
+
public?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Env-var prefixes frameworks require for values exposed to the browser. */
|
|
20
|
+
const PREFIXES = ["", "NEXT_PUBLIC_", "VITE_", "PUBLIC_", "EXPO_PUBLIC_"];
|
|
21
|
+
|
|
22
|
+
/** `base-sepolia` → `BASE_SEPOLIA`, the stem of `BASE_SEPOLIA_RPC_URL`. */
|
|
23
|
+
export const envStem = (chain: ChainRef): string => getChain(chain).key.toUpperCase().replace(/-/g, "_");
|
|
24
|
+
|
|
25
|
+
/** Read `name`, also under the public prefixes (`NEXT_PUBLIC_name`, `VITE_name` …). */
|
|
26
|
+
export function readEnv(env: Env | undefined, name: string): string | undefined {
|
|
27
|
+
const src = env ?? defaultEnv();
|
|
28
|
+
for (const p of PREFIXES) {
|
|
29
|
+
const v = src[`${p}${name}`]?.trim();
|
|
30
|
+
if (v) return v;
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const TEMPLATES: Record<
|
|
36
|
+
RpcProvider,
|
|
37
|
+
{ http: (slug: string, key: string) => string; ws: (slug: string, key: string) => string; keyVar: string }
|
|
38
|
+
> = {
|
|
39
|
+
alchemy: {
|
|
40
|
+
keyVar: "ALCHEMY_API_KEY",
|
|
41
|
+
http: (slug, key) => `https://${slug}.g.alchemy.com/v2/${key}`,
|
|
42
|
+
ws: (slug, key) => `wss://${slug}.g.alchemy.com/v2/${key}`,
|
|
43
|
+
},
|
|
44
|
+
helius: {
|
|
45
|
+
keyVar: "HELIUS_API_KEY",
|
|
46
|
+
http: (slug, key) => `https://${slug}.helius-rpc.com/?api-key=${key}`,
|
|
47
|
+
ws: (slug, key) => `wss://${slug}.helius-rpc.com/?api-key=${key}`,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* RPC endpoints for a chain, best first:
|
|
53
|
+
* 1. `<KEY>_RPC_URL` (comma-separated for several), e.g. `BASE_SEPOLIA_RPC_URL`
|
|
54
|
+
* 2. keyed providers whose API key is set (`HELIUS_API_KEY`, `ALCHEMY_API_KEY`)
|
|
55
|
+
* 3. the chain's public endpoints
|
|
56
|
+
* Every variable is also read with the `NEXT_PUBLIC_` / `VITE_` / `PUBLIC_` prefixes.
|
|
57
|
+
*/
|
|
58
|
+
export function getRpcUrls(chain: ChainRef, opts: RpcOptions = {}): string[] {
|
|
59
|
+
return resolve(getChain(chain), opts, "http");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The first of `getRpcUrls`. */
|
|
63
|
+
export function getRpcUrl(chain: ChainRef, opts: RpcOptions = {}): string {
|
|
64
|
+
return getRpcUrls(chain, opts)[0]!;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** WebSocket endpoints (`<KEY>_WS_URL`, then providers, then public; Solana derives `wss://` from overridden RPC URLs). */
|
|
68
|
+
export function getWsUrls(chain: ChainRef, opts: RpcOptions = {}): string[] {
|
|
69
|
+
return resolve(getChain(chain), opts, "ws");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function resolve(c: ChainConfig, opts: RpcOptions, kind: "http" | "ws"): string[] {
|
|
73
|
+
const env = opts.env;
|
|
74
|
+
const out: string[] = [];
|
|
75
|
+
const override = readEnv(env, `${envStem(c)}_${kind === "http" ? "RPC" : "WS"}_URL`);
|
|
76
|
+
if (override) out.push(...split(override));
|
|
77
|
+
else if (kind === "ws" && c.ecosystem === "solana") {
|
|
78
|
+
// Solana RPCs serve websockets on the same host
|
|
79
|
+
const rpc = readEnv(env, `${envStem(c)}_RPC_URL`);
|
|
80
|
+
if (rpc) out.push(...split(rpc).map((u) => u.replace(/^http/, "ws")));
|
|
81
|
+
}
|
|
82
|
+
const order = opts.providers ?? (c.ecosystem === "solana" ? ["helius", "alchemy"] : ["alchemy"]);
|
|
83
|
+
for (const p of order) {
|
|
84
|
+
const slug = c.providers?.[p];
|
|
85
|
+
const key = slug && readEnv(env, TEMPLATES[p].keyVar);
|
|
86
|
+
if (slug && key) out.push(TEMPLATES[p][kind](slug, key));
|
|
87
|
+
}
|
|
88
|
+
if (opts.public ?? true) out.push(...((kind === "http" ? c.rpcUrls : c.wsUrls) ?? []));
|
|
89
|
+
const urls = [...new Set(out)];
|
|
90
|
+
if (!urls.length)
|
|
91
|
+
throw new Error(
|
|
92
|
+
`no ${kind === "http" ? "RPC" : "WebSocket"} URL for ${c.key}; set ${envStem(c)}_${kind === "http" ? "RPC" : "WS"}_URL`,
|
|
93
|
+
);
|
|
94
|
+
return urls;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const split = (v: string) =>
|
|
98
|
+
v
|
|
99
|
+
.split(",")
|
|
100
|
+
.map((s) => s.trim())
|
|
101
|
+
.filter(Boolean);
|
|
102
|
+
|
|
103
|
+
function defaultEnv(): Env {
|
|
104
|
+
const p = (globalThis as { process?: { env?: Env } }).process;
|
|
105
|
+
return p?.env ?? {};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Replace API keys in URLs with `<redacted>`, for logs and error messages. */
|
|
109
|
+
export function redactRpcUrl(url: string): string {
|
|
110
|
+
return url.replace(/(\/v2\/)[^/?#]+/, "$1<redacted>").replace(/([?&]api-key=)[^&#]+/, "$1<redacted>");
|
|
111
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type Ecosystem = "evm" | "solana" | "sui";
|
|
2
|
+
|
|
3
|
+
export interface NativeCurrency {
|
|
4
|
+
name: string;
|
|
5
|
+
symbol: string;
|
|
6
|
+
decimals: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** One chain: plain data, no SDK objects, so it works on servers, in browsers and in build scripts. */
|
|
10
|
+
export interface ChainConfig {
|
|
11
|
+
/** Stable slug, also the env-var stem: `base-sepolia` → `BASE_SEPOLIA_RPC_URL`. */
|
|
12
|
+
key: string;
|
|
13
|
+
/** CAIP-2: `eip155:84532`, `solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1`, `sui:testnet`. */
|
|
14
|
+
id: string;
|
|
15
|
+
ecosystem: Ecosystem;
|
|
16
|
+
name: string;
|
|
17
|
+
testnet: boolean;
|
|
18
|
+
/** EVM only: the numeric chain id. */
|
|
19
|
+
chainId?: number;
|
|
20
|
+
/** Solana only: the cluster name used by explorers and CLIs. */
|
|
21
|
+
cluster?: string;
|
|
22
|
+
/** Wallet Standard chain id, where it differs from `id` (Solana wallets use `solana:devnet`, not the genesis hash). */
|
|
23
|
+
walletChain?: string;
|
|
24
|
+
nativeCurrency: NativeCurrency;
|
|
25
|
+
/**
|
|
26
|
+
* Public endpoints, in fallback order. On Sui these are fullnode base URLs for gRPC
|
|
27
|
+
* (`SuiGrpcClient`): public fullnodes no longer serve JSON-RPC.
|
|
28
|
+
*/
|
|
29
|
+
rpcUrls: readonly string[];
|
|
30
|
+
/** Sui only: the public GraphQL endpoint. */
|
|
31
|
+
graphqlUrl?: string;
|
|
32
|
+
wsUrls?: readonly string[];
|
|
33
|
+
explorer?: {
|
|
34
|
+
name: string;
|
|
35
|
+
url: string;
|
|
36
|
+
/** `{base}`-relative templates; defaults suit Etherscan/Blockscout-style explorers. */
|
|
37
|
+
tx?: string;
|
|
38
|
+
address?: string;
|
|
39
|
+
};
|
|
40
|
+
/** Network slugs for keyed RPC providers. */
|
|
41
|
+
providers?: { alchemy?: string; helius?: string };
|
|
42
|
+
}
|
package/src/viem.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* viem / wagmi glue. Import from `@codkit/config/viem` (needs `viem`).
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* const chains = [viemChain("base-sepolia")] as const;
|
|
6
|
+
* createConfig({ chains, transports: { [chains[0].id]: viemTransport("base-sepolia") } });
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
import { type Chain, defineChain, fallback, type HttpTransportConfig, http, type Transport } from "viem";
|
|
10
|
+
import { type ChainRef, getChain } from "./chains.js";
|
|
11
|
+
import { getRpcUrls, type RpcOptions } from "./rpc.js";
|
|
12
|
+
|
|
13
|
+
/** A viem `Chain` whose default RPCs are the resolved ones (override → provider → public). */
|
|
14
|
+
export function viemChain(chain: ChainRef, opts: RpcOptions = {}): Chain {
|
|
15
|
+
const c = getChain(chain);
|
|
16
|
+
if (c.ecosystem !== "evm" || c.chainId === undefined) throw new Error(`viemChain: ${c.key} is not an EVM chain`);
|
|
17
|
+
const http = getRpcUrls(c, opts);
|
|
18
|
+
return defineChain({
|
|
19
|
+
id: c.chainId,
|
|
20
|
+
name: c.name,
|
|
21
|
+
nativeCurrency: c.nativeCurrency,
|
|
22
|
+
rpcUrls: { default: { http, ...(c.wsUrls && { webSocket: [...c.wsUrls] }) } },
|
|
23
|
+
...(c.explorer && { blockExplorers: { default: { name: c.explorer.name, url: c.explorer.url } } }),
|
|
24
|
+
testnet: c.testnet,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** One `http` transport per resolved RPC, wrapped in viem's `fallback` (or a single `http` when there's one). */
|
|
29
|
+
export function viemTransport(chain: ChainRef, opts: RpcOptions & { http?: HttpTransportConfig } = {}): Transport {
|
|
30
|
+
const urls = getRpcUrls(chain, opts);
|
|
31
|
+
const transports = urls.map((u) => http(u, opts.http));
|
|
32
|
+
return transports.length === 1 ? transports[0]! : fallback(transports);
|
|
33
|
+
}
|