@somnia-chain/contracts-sdk 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/README.md +55 -0
- package/dist/gen/registry.d.ts +95667 -0
- package/dist/gen/registry.js +38285 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.js +61 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @somnia-chain/contracts-sdk
|
|
2
|
+
|
|
3
|
+
Somnia contract addresses, ABIs and chain information, typed. Generated from
|
|
4
|
+
the Somnia contract registry — the same records every Somnia deploy is
|
|
5
|
+
reconciled against.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @somnia-chain/contracts-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { getAddress, getAbi, getContract, registry } from "@somnia-chain/contracts-sdk";
|
|
13
|
+
|
|
14
|
+
getAddress("somnia-mainnet", "somnia-markets", "MarketsCore");
|
|
15
|
+
// -> "0x…", typed as the literal, with every slug and name autocompleted
|
|
16
|
+
|
|
17
|
+
const { address, abi } = getContract("somnia-mainnet", "somnia-markets", "MarketsCore");
|
|
18
|
+
// abi is `as const` — viem infers function names and argument types from it
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The whole tree is also there as one constant, `registry`, keyed
|
|
22
|
+
network → project → contract, plus one exported constant per network
|
|
23
|
+
(`somniaMainnet`, …) and `networks` with every network's chain information.
|
|
24
|
+
|
|
25
|
+
For viem, `toChain` builds a `Chain`-shaped object — the registry records no
|
|
26
|
+
public RPC endpoint, so you bring your own:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { createPublicClient, http } from "viem";
|
|
30
|
+
import { toChain } from "@somnia-chain/contracts-sdk";
|
|
31
|
+
|
|
32
|
+
const chain = toChain("somnia-mainnet", { rpcUrl: "https://your-rpc" });
|
|
33
|
+
const client = createPublicClient({ chain, transport: http() });
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Exported types: `Registry`, `NetworkSlug`, `ProjectSlug`, `ContractName`,
|
|
37
|
+
`ContractEntry`, `NetworkInfo`, `Address`.
|
|
38
|
+
|
|
39
|
+
## Chain IDs are not unique
|
|
40
|
+
|
|
41
|
+
Somnia networks are keyed by **slug**, never by chain id: a testnet regenesis
|
|
42
|
+
reuses the chain id with none of the state, so one id can name two networks
|
|
43
|
+
with different contracts at identical addresses. If an id is all you have:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { getNetworksByChainId } from "@somnia-chain/contracts-sdk";
|
|
47
|
+
|
|
48
|
+
getNetworksByChainId(50383); // -> both hideki testnets; filter on `status`
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Versioning
|
|
52
|
+
|
|
53
|
+
The package is a snapshot of the registry, published when its data moves.
|
|
54
|
+
Update the dependency to pick up newly deployed contracts — nothing is fetched
|
|
55
|
+
at runtime.
|