@effectstream/midnight-contracts 0.100.14 → 0.100.16

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.
Files changed (2) hide show
  1. package/README.md +59 -89
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,73 +1,53 @@
1
- # @effectstream/midnight
1
+ # @effectstream/midnight-contracts
2
2
 
3
- Utilities for working with Midnight contracts in EffectStream.
3
+ Utilities for reading and deploying Midnight contracts from inside an Effectstream node or test. Two functions: `readMidnightContract` to load contract metadata + ABI by name, and `deployMidnightContract` to deploy and persist the resulting address.
4
4
 
5
- ## read-contract
5
+ - Reads contract files by name, searching from the current working directory upward.
6
+ - Supports per-network files (`contract-counter.undeployed.json`, `contract-counter.testnet.json`) without hardcoded paths.
7
+ - Deploys against the local Midnight stack by default; pass `NetworkUrls` to point at another environment.
8
+ - Persists the deployed address to a JSON file so subsequent reads pick it up automatically.
6
9
 
7
- Provides a context-aware function to read Midnight contract information from JSON files.
10
+ ## Install
8
11
 
9
- ### Usage
10
-
11
- ```typescript
12
- import { readMidnightContract } from "@effectstream/midnight-contracts/read-contract";
13
-
14
- // Read contract for the current network (defaults to contract-counter.<networkId>.json)
15
- const contractInfo = readMidnightContract("contract-counter");
16
-
17
- // Read contract for another network (e.g., preview)
18
- const previewInfo = readMidnightContract(
19
- "contract-counter",
20
- { networkId: "preview" },
21
- );
22
-
23
- // With explicit base directory (still respects network-specific files)
24
- const customDirInfo = readMidnightContract(
25
- "contract-counter",
26
- { baseDir: "/path/to/contracts", networkId: "undeployed" },
27
- );
12
+ ```bash
13
+ bun add @effectstream/midnight-contracts
14
+ # or
15
+ npm install @effectstream/midnight-contracts
28
16
  ```
29
17
 
30
- ### Features
18
+ Requires a reachable Midnight node, proof server, and indexer. The defaults match what `@effectstream/orchestrator`'s Midnight step boots locally.
31
19
 
32
- - **Context-aware**: Automatically finds contract files by recursively searching from the current working directory upward through the directory tree
33
- - **Flexible directory structure**: Works with any directory structure - no hardcoded paths required
34
- - **Multiple contracts**: Supports reading multiple contracts with different filenames
35
- - **Caching**: Results are cached per contract location, name, and filename combination
36
- - **Dynamic compiler detection**: Automatically finds the compiler subdirectory in `src/managed/`
20
+ ## Standalone usage
37
21
 
38
- ### Function Signature
22
+ ### Read a contract
39
23
 
40
24
  ```typescript
41
- function readMidnightContract(
42
- contractName: string,
43
- contractFileName?: string,
44
- options?: { baseDir?: string; networkId?: string }
45
- ): MidnightContractInfo
46
- ```
47
-
48
- ### Parameters
49
-
50
- - `contractName`: The name of the contract directory (e.g., 'contract-counter', 'contract-eip-20')
51
- - `contractFileName`: Optional override. Defaults to `${contractName}.${networkId}.json`, so you can keep per-network files.
52
- - `options`: Optional configuration object. `baseDir` overrides the search location, and `networkId` selects the file (default: `undeployed`).
25
+ import { readMidnightContract } from "@effectstream/midnight-contracts/read-contract";
53
26
 
54
- ### Returns
27
+ // Defaults to contract-counter.<networkId>.json, where networkId is "undeployed".
28
+ const local = readMidnightContract("contract-counter");
55
29
 
56
- `MidnightContractInfo` object containing:
57
- - `contractAddress`: The deployed contract address
58
- - `contractInfo`: Compiler-generated contract information (circuits, certificates, contracts)
59
- - `zkConfigPath`: Path to the zk configuration directory
30
+ // Read the same contract on a different network.
31
+ const preview = readMidnightContract("contract-counter", { networkId: "preview" });
60
32
 
61
- ## deploy
33
+ // Override the search base if your contracts live outside the CWD tree.
34
+ const custom = readMidnightContract("contract-counter", {
35
+ baseDir: "/path/to/contracts",
36
+ networkId: "undeployed",
37
+ });
38
+ ```
62
39
 
63
- Deploys a Midnight contract using the provided configuration. This function is context-aware and automatically finds the contract directory and zkConfigPath.
40
+ Returns `{ contractAddress, contractInfo, zkConfigPath }`. Results are cached per `(location, name, filename)` tuple so repeated reads in the same process are free.
64
41
 
65
- ### Usage
42
+ ### Deploy a contract
66
43
 
67
44
  ```typescript
68
- import { deployMidnightContract, type DeployConfig, type NetworkUrls } from "@effectstream/midnight-contracts/deploy";
45
+ import {
46
+ deployMidnightContract,
47
+ type DeployConfig,
48
+ type NetworkUrls,
49
+ } from "@effectstream/midnight-contracts/deploy";
69
50
 
70
- // Deploy with default network URLs (local undeployed endpoints)
71
51
  const config: DeployConfig = {
72
52
  contractName: "contract-counter",
73
53
  contractFileName: "contract-counter.json",
@@ -77,58 +57,48 @@ const config: DeployConfig = {
77
57
  initialPrivateState: { privateCounter: 0 },
78
58
  };
79
59
 
80
- const contractAddress = await deployMidnightContract(config);
60
+ const address = await deployMidnightContract(config);
61
+ ```
62
+
63
+ To deploy against a non-default stack, pass `NetworkUrls`:
81
64
 
82
- // Deploy with custom network URLs
83
- const networkUrls: NetworkUrls = {
65
+ ```typescript
66
+ const network: NetworkUrls = {
84
67
  indexer: "http://localhost:8088/api/v3/graphql",
85
68
  indexerWS: "ws://localhost:8088/api/v3/graphql/ws",
86
69
  node: "http://localhost:9944",
87
70
  proofServer: "http://localhost:6300",
88
71
  };
89
72
 
90
- const contractAddress = await deployMidnightContract(config, networkUrls);
73
+ const address = await deployMidnightContract(config, network);
91
74
  ```
92
75
 
93
- ### Function Signature
76
+ The deploy helper creates and funds a wallet from the genesis mint seed, runs the deployment, and writes the resulting address to `${contractName}.${networkId}.json` so the next `readMidnightContract` call picks it up.
94
77
 
95
- ```typescript
96
- function deployMidnightContract(
97
- config: DeployConfig,
98
- networkUrls?: NetworkUrls
99
- ): Promise<string>
100
- ```
78
+ ## Inside Effectstream
79
+
80
+ `@effectstream/midnight-contracts` is the seam between Midnight contract artifacts on disk and the code that reads or deploys them. Templates that target Midnight call `readMidnightContract` from their node startup to resolve the on-chain address; the orchestrator's deploy step calls `deployMidnightContract` to put one there in the first place. On the sync side, `@effectstream/sync`'s `MidnightFetcher` consumes the node behind both calls.
81
+
82
+ ## Key exports
83
+
84
+ `@effectstream/midnight-contracts/read-contract`:
101
85
 
102
- ### Parameters
86
+ - `readMidnightContract(name, options?)`: returns `{ contractAddress, contractInfo, zkConfigPath }`. `options.networkId` selects per-network files; `options.baseDir` overrides the search base.
103
87
 
104
- - `config`: Deployment configuration object containing:
105
- - `contractName`: Name of the contract directory (e.g., "contract-counter", "contract-eip-20")
106
- - `contractFileName`: Base filename for the contract address. The deployed file will append the network id (e.g., `contract-counter.undeployed.json`).
107
- - `contractClass`: The Contract class to deploy
108
- - `witnesses`: Witness definitions
109
- - `privateStateId`: On-chain private state ID
110
- - `initialPrivateState`: Initial private state object
111
- - `deployArgs`: Optional deployment arguments array
112
- - `privateStateStoreName`: Optional private state store name (defaults to contractName-based value)
113
- - `baseDir`: Optional base directory override for finding contracts
114
- - `logDir`: Optional log directory path
115
- - `extractWalletAddress`: Optional flag to extract wallet address info (for contracts that need initialOwner)
88
+ `@effectstream/midnight-contracts/deploy`:
116
89
 
117
- - `networkUrls`: Optional network endpoint URLs. If not provided, defaults to local undeployed endpoints:
118
- - `indexer`: GraphQL indexer HTTP endpoint (default: "http://127.0.0.1:8088/api/v3/graphql")
119
- - `indexerWS`: GraphQL indexer WebSocket endpoint (default: "ws://127.0.0.1:8088/api/v3/graphql/ws")
120
- - `node`: Midnight node RPC endpoint (default: "http://127.0.0.1:9944")
121
- - `proofServer`: Proof server HTTP endpoint (default: "http://127.0.0.1:6300")
90
+ - `deployMidnightContract(config, networkUrls?)`: deploys and returns the address. Persists the address to a JSON file.
91
+ - `DeployConfig`, `NetworkUrls`: input types.
122
92
 
123
- ### Returns
93
+ ## Examples
124
94
 
125
- A Promise that resolves to the deployed contract address as a string.
95
+ End-to-end usage in templates:
126
96
 
127
- ### Features
97
+ - [`templates/evm-midnight-v2/`](https://github.com/effectstream/effectstream/tree/main/templates/evm-midnight-v2)
98
+ - [`templates/zswap-da/`](https://github.com/effectstream/effectstream/tree/main/templates/zswap-da)
128
99
 
129
- - **Context-aware**: Automatically finds contract directory by recursively searching from the current working directory
130
- - **Flexible network configuration**: Use default local endpoints or provide custom network URLs
131
- - **Automatic wallet setup**: Creates and funds a wallet automatically using the genesis mint seed
132
- - **Dynamic compiler detection**: Automatically finds the compiler subdirectory in `src/managed/`
133
- - **Contract address persistence**: Saves the deployed contract address to a JSON file
100
+ ## Links
134
101
 
102
+ - Docs: https://effectstream.github.io/docs/packages/chains/midnight-contracts
103
+ - Source: https://github.com/effectstream/effectstream/tree/main/packages/chains/midnight-contracts
104
+ - Midnight: https://midnight.network
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effectstream/midnight-contracts",
3
- "version": "0.100.14",
3
+ "version": "0.100.16",
4
4
  "license": "MIT",
5
5
  "homepage": "https://effectstream.github.io/docs/",
6
6
  "repository": {
@@ -20,7 +20,7 @@
20
20
  "./types": "./src/types.ts"
21
21
  },
22
22
  "dependencies": {
23
- "@effectstream/utils": "0.100.14",
23
+ "@effectstream/utils": "0.100.16",
24
24
  "@scure/bip39": "^2.0.1",
25
25
  "dotenv": "^16.4.7",
26
26
  "@midnight-ntwrk/wallet": "5.0.0",