@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 codkit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,71 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @codkit/config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Chain registry, RPC resolution and env validation for dapps on EVM, Solana and Sui. Plain data at runtime: the core imports no chain SDK, so it works on servers, in browsers and in build scripts.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @codkit/config
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Chains
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { chains, getChain, listChains, explorerTxUrl } from "@codkit/config";
|
|
13
|
+
|
|
14
|
+
chains["base-sepolia"]; // { key, id: "eip155:84532", ecosystem: "evm", chainId, nativeCurrency, rpcUrls, explorer, … }
|
|
15
|
+
getChain("solana:devnet"); // look up by key, CAIP-2 id, Wallet Standard id or EVM chain id (84532)
|
|
16
|
+
listChains({ ecosystem: "evm", testnet: true });
|
|
17
|
+
explorerTxUrl("solana-devnet", signature); // https://explorer.solana.com/tx/…?cluster=devnet
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Built in: Ethereum, Base, Optimism, Arbitrum, Polygon, BNB, Avalanche and Celo (mainnet + testnet each), plus Linea Sepolia, Scroll Sepolia, Unichain Sepolia, Monad testnet and Anvil. Solana mainnet, devnet, testnet and localnet. Sui mainnet, testnet, devnet and localnet. The EVM entries are generated from `viem/chains` (`pnpm --filter @codkit/config gen`). For anything else, use `defineChain({...})`; every function accepts the result.
|
|
21
|
+
|
|
22
|
+
Sui note: public fullnodes no longer serve JSON-RPC. `rpcUrls` are base URLs for `SuiGrpcClient`, and `graphqlUrl` is the GraphQL endpoint.
|
|
23
|
+
|
|
24
|
+
## RPC URLs with fallbacks
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { getRpcUrl, getRpcUrls } from "@codkit/config";
|
|
28
|
+
|
|
29
|
+
getRpcUrls("base-sepolia");
|
|
30
|
+
// 1. BASE_SEPOLIA_RPC_URL (comma-separated for several)
|
|
31
|
+
// 2. https://base-sepolia.g.alchemy.com/v2/$ALCHEMY_API_KEY (if set)
|
|
32
|
+
// 3. https://sepolia.base.org (public)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
| Variable | Effect |
|
|
36
|
+
| ------------------------------- | -------------------------------------------------------------------------------------------- |
|
|
37
|
+
| `<KEY>_RPC_URL`, `<KEY>_WS_URL` | Your endpoints first. `<KEY>` is the chain key in upper snake case: `SOLANA_DEVNET_RPC_URL`. |
|
|
38
|
+
| `ALCHEMY_API_KEY` | Adds Alchemy on the EVM chains and Solana. |
|
|
39
|
+
| `HELIUS_API_KEY` | Adds Helius on Solana mainnet and devnet (tried before Alchemy). |
|
|
40
|
+
|
|
41
|
+
Each variable is also read with the `NEXT_PUBLIC_`, `VITE_`, `PUBLIC_` and `EXPO_PUBLIC_` prefixes. On a server the default source is `process.env`. In the browser, frameworks only inline variables you name, so pass them in: `getRpcUrls(chain, { env: import.meta.env })` with Vite, or an object of `process.env.NEXT_PUBLIC_…` values with Next.js. Keys that reach the browser are public, so restrict them by domain in the provider's dashboard.
|
|
42
|
+
|
|
43
|
+
`getWsUrls` does the same for WebSockets; on Solana it derives `wss://` from an overridden RPC URL. `redactRpcUrl(url)` hides keys in logs.
|
|
44
|
+
|
|
45
|
+
## viem / wagmi
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { viemChain, viemTransport } from "@codkit/config/viem"; // needs viem
|
|
49
|
+
|
|
50
|
+
const baseSepolia = viemChain("base-sepolia");
|
|
51
|
+
createConfig({ chains: [baseSepolia], transports: { [baseSepolia.id]: viemTransport("base-sepolia") } });
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`viemTransport` wraps every resolved URL in viem's `fallback`, so a rate-limited endpoint fails over to the next.
|
|
55
|
+
|
|
56
|
+
## Env validation
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { parseEnv, rpcEnvSchema } from "@codkit/config";
|
|
60
|
+
import { z } from "zod";
|
|
61
|
+
|
|
62
|
+
export const env = parseEnv(rpcEnvSchema(["base-sepolia", "solana-devnet"]).extend({ DATABASE_URL: z.url() }));
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`rpcEnvSchema` covers the variables above plus `WALLETCONNECT_PROJECT_ID`; pass `{ prefix: "NEXT_PUBLIC_" }` for client builds. `parseEnv` treats empty strings as unset and throws an `EnvError` that lists every bad variable at once, without echoing values.
|
|
66
|
+
|
|
67
|
+
## Example
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pnpm --filter @codkit/config example # resolves Base Sepolia, Solana devnet and Sui testnet, then calls each
|
|
71
|
+
```
|