@twin.org/move-to-json 0.0.1 → 0.0.2-next.2
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 +329 -8
- package/dist/cjs/index.cjs +629 -104
- package/dist/esm/index.mjs +622 -104
- package/dist/locales/en.json +197 -32
- package/dist/types/commands/build.d.ts +18 -0
- package/dist/types/commands/deploy.d.ts +21 -0
- package/dist/types/index.d.ts +9 -3
- package/dist/types/models/IContractData.d.ts +21 -0
- package/dist/types/models/INetworkConfig.d.ts +47 -0
- package/dist/types/models/ISmartContractDeployments.d.ts +8 -0
- package/dist/types/models/networkTypes.d.ts +21 -0
- package/dist/types/utils/envSetup.d.ts +21 -0
- package/dist/types/utils/iotaUtils.d.ts +5 -0
- package/dist/types/utils/moveToJsonUtils.d.ts +6 -0
- package/docs/changelog.md +23 -0
- package/docs/examples.md +67 -78
- package/docs/reference/functions/actionCommandBuild.md +33 -0
- package/docs/reference/functions/actionCommandDeploy.md +39 -0
- package/docs/reference/functions/buildCommandBuild.md +17 -0
- package/docs/reference/functions/buildCommandDeploy.md +17 -0
- package/docs/reference/functions/getDeploymentMnemonic.md +23 -0
- package/docs/reference/functions/getDeploymentSeed.md +23 -0
- package/docs/reference/functions/searchDirectoryForMoveToml.md +23 -0
- package/docs/reference/functions/validateDeploymentEnvironment.md +21 -0
- package/docs/reference/functions/verifyIotaSDK.md +13 -0
- package/docs/reference/index.md +14 -5
- package/docs/reference/interfaces/IContractData.md +35 -0
- package/docs/reference/interfaces/INetworkConfig.md +83 -0
- package/docs/reference/type-aliases/ISmartContractDeployments.md +5 -0
- package/docs/reference/type-aliases/NetworkTypes.md +5 -0
- package/docs/reference/variables/NetworkTypes.md +25 -0
- package/locales/en.json +144 -32
- package/package.json +9 -5
- package/dist/types/commands/moveToJson.d.ts +0 -17
- package/dist/types/models/ICompiledModules.d.ts +0 -18
- package/dist/types/models/platformTypes.d.ts +0 -17
- package/docs/reference/functions/actionCommandMoveToJson.md +0 -33
- package/docs/reference/functions/buildCommandMoveToJson.md +0 -17
- package/docs/reference/interfaces/ICompiledModules.md +0 -9
- package/docs/reference/type-aliases/PlatformTypes.md +0 -5
- package/docs/reference/variables/PlatformTypes.md +0 -19
package/README.md
CHANGED
|
@@ -1,21 +1,342 @@
|
|
|
1
1
|
# TWIN Move to JSON
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Tool to convert Move source files to JSON with network-specific deployment support.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
### IOTA CLI Installation
|
|
8
|
+
|
|
9
|
+
Before using this tool, you need to install the IOTA CLI. The simplest way is using Homebrew:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Install IOTA CLI using Homebrew (macOS/Linux/WSL)
|
|
13
|
+
brew install iotaledger/tap/iota
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**Alternative installation methods:**
|
|
17
|
+
|
|
18
|
+
For other platforms or installation from source, see the [official IOTA installation guide](https://docs.iota.org/developer/getting-started/install-iota).
|
|
19
|
+
|
|
20
|
+
**Verify installation:**
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
iota --version
|
|
24
|
+
```
|
|
4
25
|
|
|
5
26
|
## Installation
|
|
6
27
|
|
|
7
28
|
```shell
|
|
8
|
-
npm install @twin.org/move-to-json
|
|
29
|
+
npm install -g @twin.org/move-to-json
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Build contracts for mainnet using environment variables (recommended)
|
|
36
|
+
npx move-to-json build "src/**/*.move" --load-env configs/mainnet.env --output smart-contract-deployments.json
|
|
37
|
+
|
|
38
|
+
# Deploy to mainnet using environment variables (recommended)
|
|
39
|
+
npx move-to-json deploy --load-env configs/mainnet.env --contracts smart-contract-deployments.json
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Environment Setup for Production Deployments
|
|
43
|
+
|
|
44
|
+
### Required Environment Variables
|
|
45
|
+
|
|
46
|
+
For production deployments, you need to set up environment variables containing your deployment credentials. The tool uses network-specific configuration files located in the `configs/` directory.
|
|
47
|
+
|
|
48
|
+
#### 1. Create Environment Files
|
|
49
|
+
|
|
50
|
+
Copy the environment templates for each network you plan to use:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Copy environment templates for each network
|
|
54
|
+
cp configs/testnet.env.example configs/testnet.env
|
|
55
|
+
cp configs/devnet.env.example configs/devnet.env
|
|
56
|
+
cp configs/mainnet.env.example configs/mainnet.env
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Note:** Only copy the environment files for the networks you actually plan to deploy to. For development, you typically only need `testnet.env` and `devnet.env`.
|
|
60
|
+
|
|
61
|
+
#### 2. Generate Deployment Mnemonics
|
|
62
|
+
|
|
63
|
+
Use the wallet CLI to generate secure mnemonics and then manually update the appropriate network configuration files with the generated mnemonic.
|
|
64
|
+
|
|
65
|
+
### Environment Variable Reference
|
|
66
|
+
|
|
67
|
+
Each network has its own configuration file in the `configs/` directory with the required deployment mnemonic:
|
|
68
|
+
|
|
69
|
+
| Network | File | Required Variable |
|
|
70
|
+
| ------- | --------------------- | ------------------- |
|
|
71
|
+
| Testnet | `configs/testnet.env` | `DEPLOYER_MNEMONIC` |
|
|
72
|
+
| Devnet | `configs/devnet.env` | `DEPLOYER_MNEMONIC` |
|
|
73
|
+
| Mainnet | `configs/mainnet.env` | `DEPLOYER_MNEMONIC` |
|
|
74
|
+
|
|
75
|
+
### Security Best Practices
|
|
76
|
+
|
|
77
|
+
#### Local Development
|
|
78
|
+
|
|
79
|
+
- Store credentials in `configs/*.env` files (never commit to git - only commit `.example` files)
|
|
80
|
+
- Use test mnemonics with faucet funds for testnet/devnet
|
|
81
|
+
- Use dedicated deployment wallets separate from personal wallets
|
|
82
|
+
|
|
83
|
+
#### CI/CD and Production
|
|
84
|
+
|
|
85
|
+
- Store credentials in GitHub Secrets or your CI/CD secrets manager
|
|
86
|
+
- Use hardware wallets or HSM for mainnet deployment keys
|
|
87
|
+
- Implement approval workflows for mainnet deployments
|
|
88
|
+
- Monitor wallet balances and deployment costs
|
|
89
|
+
|
|
90
|
+
### Generating Credentials
|
|
91
|
+
|
|
92
|
+
#### 1. Generate Mnemonic and Seed
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# Generate a new 24-word mnemonic and save to wallet.env
|
|
96
|
+
npx "@twin.org/wallet-cli" mnemonic --env wallet.env
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### 2. Generate Addresses from Seed
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Generate 5 addresses and save to address.env
|
|
103
|
+
npx "@twin.org/wallet-cli" address --load-env wallet.env --seed '!SEED' --count 5 --env address.env
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Commands
|
|
107
|
+
|
|
108
|
+
### build
|
|
109
|
+
|
|
110
|
+
Compile Move contracts for a specific network:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
# Using environment variables (recommended)
|
|
114
|
+
npx move-to-json build "src/**/*.move" --load-env configs/<network>.env [--output <file>]
|
|
115
|
+
|
|
116
|
+
# Using explicit network flag
|
|
117
|
+
npx move-to-json build "src/**/*.move" --network <network> [--output <file>]
|
|
118
|
+
|
|
119
|
+
# If installed globally
|
|
120
|
+
move-to-json build "src/**/*.move" --load-env configs/<network>.env [--output <file>]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Options:**
|
|
124
|
+
|
|
125
|
+
- `--network <network>` - Target network (testnet/devnet/mainnet) **[Optional if using --load-env]**
|
|
126
|
+
- `--load-env <file>` - Load environment variables from file (must contain NETWORK variable)
|
|
127
|
+
- `--output <file>` - Output JSON file (default: smart-contract-deployments.json)
|
|
128
|
+
|
|
129
|
+
**What it does:**
|
|
130
|
+
|
|
131
|
+
1. Reads network from `--network` flag or `NETWORK` environment variable
|
|
132
|
+
2. Validates environment variables for the target network
|
|
133
|
+
3. Cleans build artifacts and Move.lock files
|
|
134
|
+
4. Compiles contracts using unified Move.toml (same bytecode for all networks)
|
|
135
|
+
5. Generates network-aware JSON with package IDs and base64 modules
|
|
136
|
+
|
|
137
|
+
**Key Changes:**
|
|
138
|
+
|
|
139
|
+
- **Unified Move.toml**: Uses single Move.toml file with `framework/testnet` for consistent builds
|
|
140
|
+
- **Network-agnostic compilation**: Same bytecode works across all networks
|
|
141
|
+
- **Environment-aware**: Network targeting handled by IOTA CLI environments, not Move.toml
|
|
142
|
+
|
|
143
|
+
**Example:**
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
# Build for testnet using environment variables (recommended)
|
|
147
|
+
npx move-to-json build "tests/fixtures/sources/**/*.move" --load-env configs/testnet.env --output tests/fixtures/smart-contract-deployments/smart-contract-deployments.json
|
|
148
|
+
|
|
149
|
+
# Build for mainnet using environment variables (recommended)
|
|
150
|
+
npx move-to-json build "src/contracts/**/*.move" --load-env configs/mainnet.env --output smart-contract-deployments.json
|
|
151
|
+
|
|
152
|
+
# Alternative: using explicit network flag
|
|
153
|
+
npx move-to-json build "tests/fixtures/sources/**/*.move" --network testnet --output tests/fixtures/smart-contract-deployments/smart-contract-deployments.json
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### deploy
|
|
157
|
+
|
|
158
|
+
Deploy compiled contracts to the specified network:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
# Using environment variables (recommended)
|
|
162
|
+
npx move-to-json deploy --load-env configs/<network>.env [--contracts <file>] [options]
|
|
163
|
+
|
|
164
|
+
# Using explicit network flag
|
|
165
|
+
npx move-to-json deploy --network <network> [--load-env configs/<network>.env] [options]
|
|
166
|
+
|
|
167
|
+
# If installed globally
|
|
168
|
+
move-to-json deploy --load-env configs/<network>.env [--contracts <file>] [options]
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**Options:**
|
|
172
|
+
|
|
173
|
+
- `--network <network>` - Network identifier (testnet/devnet/mainnet) **[Optional if using --load-env]**
|
|
174
|
+
- `--load-env <file>` - Load environment variables from file (must contain NETWORK variable)
|
|
175
|
+
- `--contracts <file>` - Compiled modules JSON file (default: smart-contract-deployments.json)
|
|
176
|
+
- `--dry-run` - Simulate deployment without executing
|
|
177
|
+
- `--force` - Force redeployment of existing packages
|
|
178
|
+
|
|
179
|
+
**What it does:**
|
|
180
|
+
|
|
181
|
+
1. Switches IOTA CLI to target network environment
|
|
182
|
+
2. Loads environment variables from the file specified via `--load-env` flag
|
|
183
|
+
3. Validates deployment credentials are available
|
|
184
|
+
4. Checks wallet balance against gas requirements
|
|
185
|
+
5. Loads compiled contracts from JSON
|
|
186
|
+
6. Deploys using IOTA CLI with active network environment
|
|
187
|
+
7. Extracts and saves both Package ID and UpgradeCap ID
|
|
188
|
+
8. Updates JSON with deployed package information
|
|
189
|
+
|
|
190
|
+
**Key Changes:**
|
|
191
|
+
|
|
192
|
+
- **Environment switching**: Automatically switches IOTA CLI to target network
|
|
193
|
+
- **Network targeting**: Uses IOTA CLI environments instead of Move.toml configuration
|
|
194
|
+
- **Consistent deployment**: Same compiled bytecode deployed to all networks
|
|
195
|
+
- **UpgradeCap tracking**: Captures and stores UpgradeCap object ID for future package upgrades
|
|
196
|
+
|
|
197
|
+
**Prerequisites:**
|
|
198
|
+
Ensure IOTA CLI environments are configured:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
# Check available environments
|
|
202
|
+
iota client envs
|
|
203
|
+
|
|
204
|
+
# Configure networks if missing
|
|
205
|
+
iota client new-env --alias testnet --rpc https://fullnode.testnet.iota.cafe:443
|
|
206
|
+
iota client new-env --alias mainnet --rpc https://api.mainnet.iota.cafe
|
|
207
|
+
iota client new-env --alias devnet --rpc https://api.devnet.iota.cafe
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**Example:**
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
# Deploy to testnet using environment variables (recommended)
|
|
214
|
+
npx move-to-json deploy --load-env configs/testnet.env --contracts tests/fixtures/smart-contract-deployments/smart-contract-deployments.json
|
|
215
|
+
|
|
216
|
+
# Deploy to mainnet using environment variables (recommended)
|
|
217
|
+
npx move-to-json deploy --load-env configs/mainnet.env --contracts tests/fixtures/smart-contract-deployments/smart-contract-deployments.json
|
|
218
|
+
|
|
219
|
+
# Dry run (simulation)
|
|
220
|
+
npx move-to-json deploy --load-env configs/testnet.env --contracts tests/fixtures/smart-contract-deployments/smart-contract-deployments.json --dry-run
|
|
9
221
|
```
|
|
10
222
|
|
|
11
|
-
|
|
223
|
+
**Output:**
|
|
224
|
+
The deployment saves both Package ID and UpgradeCap ID:
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
{
|
|
228
|
+
"testnet": {
|
|
229
|
+
"packageId": "0x...",
|
|
230
|
+
"package": "base64data...",
|
|
231
|
+
"deployedPackageId": "0x239ad3ea39f0910a4dc4c98161bcde948fb5ed0d7d7ae6d9a593239c43af748e",
|
|
232
|
+
"upgradeCap": "0xfd6269c28e3931e41aa9d9e08ffabb8162cf1fd0baaef14094b4442e6c743edf"
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**Important Note on UpgradeCap:**
|
|
238
|
+
The UpgradeCap ID is crucial for package upgrades. Keep this secure - it's required to upgrade your deployed packages in the future.
|
|
239
|
+
|
|
240
|
+
## Unified Move.toml Approach
|
|
241
|
+
|
|
242
|
+
The tool now uses a **unified Move.toml approach** that eliminates the need for network-specific Move.toml files. This provides better consistency and reduces complexity.
|
|
12
243
|
|
|
13
|
-
|
|
244
|
+
### Single Move.toml Configuration
|
|
14
245
|
|
|
15
|
-
|
|
246
|
+
Instead of multiple `Move.toml.{network}` files, use a single `Move.toml` file:
|
|
16
247
|
|
|
17
|
-
|
|
248
|
+
```toml
|
|
249
|
+
[package]
|
|
250
|
+
name = "my_contract"
|
|
251
|
+
version = "0.0.1"
|
|
252
|
+
edition = "2024.beta"
|
|
253
|
+
|
|
254
|
+
[dependencies]
|
|
255
|
+
Iota = {
|
|
256
|
+
git = "https://github.com/iotaledger/iota.git",
|
|
257
|
+
subdir = "crates/iota-framework/packages/iota-framework",
|
|
258
|
+
rev = "framework/testnet"
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
[addresses]
|
|
262
|
+
my_contract = "0x0"
|
|
263
|
+
|
|
264
|
+
[dev-dependencies]
|
|
265
|
+
# Optional: Override dependencies for testing
|
|
266
|
+
# Iota = { git = "https://github.com/iotaledger/iota.git", subdir = "crates/iota-framework/packages/iota-framework", rev = "framework/devnet", override = true }
|
|
267
|
+
|
|
268
|
+
[dev-addresses]
|
|
269
|
+
# Optional: Override addresses for development
|
|
270
|
+
# my_contract = "0x1234"
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Framework Version Strategy
|
|
274
|
+
|
|
275
|
+
- **Development/Testing**: Use `framework/testnet` for all networks
|
|
276
|
+
- **Production**: Same `framework/testnet` works for mainnet deployment
|
|
277
|
+
- **Consistency**: Same bytecode compiles for all target networks
|
|
278
|
+
|
|
279
|
+
### Network Targeting
|
|
280
|
+
|
|
281
|
+
Network targeting is handled through **IOTA CLI environments**, not Move.toml:
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
# Build once - same bytecode for all networks
|
|
285
|
+
iota move build
|
|
286
|
+
|
|
287
|
+
# Deploy to different networks by switching environments
|
|
288
|
+
iota client switch --env testnet && iota client publish
|
|
289
|
+
iota client switch --env mainnet && iota client publish
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Benefits
|
|
293
|
+
|
|
294
|
+
- ✅ **Consistent builds** across all networks
|
|
295
|
+
- ✅ **Reduced complexity** - no file copying
|
|
296
|
+
- ✅ **Industry standard** approach
|
|
297
|
+
- ✅ **Better maintainability** - single source of truth
|
|
298
|
+
- ✅ **Eliminated build conflicts** between networks
|
|
299
|
+
|
|
300
|
+
## Package Upgrades and UpgradeCap Management
|
|
301
|
+
|
|
302
|
+
When you deploy a Move package on IOTA, the network creates an **UpgradeCap** (Upgrade Capability) object that controls the ability to upgrade that package. This tool automatically captures and stores the UpgradeCap ID for future use.
|
|
303
|
+
|
|
304
|
+
### What is an UpgradeCap?
|
|
305
|
+
|
|
306
|
+
The UpgradeCap is a special object that:
|
|
307
|
+
|
|
308
|
+
- **Controls package upgrades**: Only the holder can upgrade the package
|
|
309
|
+
- **Is created once**: Generated during initial package deployment
|
|
310
|
+
- **Must be preserved**: Lost UpgradeCap = no future upgrades possible
|
|
311
|
+
- **Is network-specific**: Each network deployment gets its own UpgradeCap
|
|
312
|
+
|
|
313
|
+
### UpgradeCap Storage
|
|
314
|
+
|
|
315
|
+
The tool stores UpgradeCap IDs in the smart-contract-deployments.json file:
|
|
316
|
+
|
|
317
|
+
```json
|
|
318
|
+
{
|
|
319
|
+
"testnet": {
|
|
320
|
+
"packageId": "0xabc123...",
|
|
321
|
+
"package": "base64data...",
|
|
322
|
+
"deployedPackageId": "0x239ad3ea39f0910a4dc4c98161bcde948fb5ed0d7d7ae6d9a593239c43af748e",
|
|
323
|
+
"upgradeCap": "0xfd6269c28e3931e41aa9d9e08ffabb8162cf1fd0baaef14094b4442e6c743edf"
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### Using UpgradeCap for Package Upgrades
|
|
329
|
+
|
|
330
|
+
To upgrade a deployed package, you'll need the UpgradeCap ID:
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
# Example upgrade command (using IOTA CLI)
|
|
334
|
+
iota client call --package 0x2 --module package --function upgrade \
|
|
335
|
+
--args 0xfd6269c28e3931e41aa9d9e08ffabb8162cf1fd0baaef14094b4442e6c743edf \
|
|
336
|
+
--gas-budget 50000000
|
|
337
|
+
```
|
|
18
338
|
|
|
19
|
-
##
|
|
339
|
+
## Contributing
|
|
20
340
|
|
|
21
|
-
|
|
341
|
+
To contribute to this package see the guidelines for building and publishing in
|
|
342
|
+
[CONTRIBUTING](./CONTRIBUTING.md)
|