@effectstream/midnight-contracts 0.100.15 → 0.100.17
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 +59 -89
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,73 +1,53 @@
|
|
|
1
|
-
# @effectstream/midnight
|
|
1
|
+
# @effectstream/midnight-contracts
|
|
2
2
|
|
|
3
|
-
Utilities for
|
|
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
|
-
|
|
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
|
-
|
|
10
|
+
## Install
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
18
|
+
Requires a reachable Midnight node, proof server, and indexer. The defaults match what `@effectstream/orchestrator`'s Midnight step boots locally.
|
|
31
19
|
|
|
32
|
-
|
|
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
|
-
###
|
|
22
|
+
### Read a contract
|
|
39
23
|
|
|
40
24
|
```typescript
|
|
41
|
-
|
|
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
|
-
|
|
27
|
+
// Defaults to contract-counter.<networkId>.json, where networkId is "undeployed".
|
|
28
|
+
const local = readMidnightContract("contract-counter");
|
|
55
29
|
|
|
56
|
-
|
|
57
|
-
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
###
|
|
42
|
+
### Deploy a contract
|
|
66
43
|
|
|
67
44
|
```typescript
|
|
68
|
-
import {
|
|
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
|
|
60
|
+
const address = await deployMidnightContract(config);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
To deploy against a non-default stack, pass `NetworkUrls`:
|
|
81
64
|
|
|
82
|
-
|
|
83
|
-
const
|
|
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
|
|
73
|
+
const address = await deployMidnightContract(config, network);
|
|
91
74
|
```
|
|
92
75
|
|
|
93
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
86
|
+
- `readMidnightContract(name, options?)`: returns `{ contractAddress, contractInfo, zkConfigPath }`. `options.networkId` selects per-network files; `options.baseDir` overrides the search base.
|
|
103
87
|
|
|
104
|
-
-
|
|
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`:
|
|
118
|
-
|
|
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
|
-
|
|
93
|
+
## Examples
|
|
124
94
|
|
|
125
|
-
|
|
95
|
+
End-to-end usage in templates:
|
|
126
96
|
|
|
127
|
-
|
|
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
|
-
|
|
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,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectstream/midnight-contracts",
|
|
3
|
-
"version": "0.100.
|
|
3
|
+
"version": "0.100.17",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://effectstream.github.io/docs/",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/
|
|
8
|
+
"url": "https://github.com/effectstream/effectstream",
|
|
9
9
|
"directory": "packages/chains/midnight-contracts"
|
|
10
10
|
},
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/
|
|
12
|
+
"url": "https://github.com/effectstream/effectstream/issues"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
15
|
".": "./src/mod.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"./types": "./src/types.ts"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@effectstream/utils": "0.100.
|
|
23
|
+
"@effectstream/utils": "0.100.17",
|
|
24
24
|
"@scure/bip39": "^2.0.1",
|
|
25
25
|
"dotenv": "^16.4.7",
|
|
26
26
|
"@midnight-ntwrk/wallet": "5.0.0",
|