Skip to content

Commit e8e94e4

Browse files
committed
Merge branch 'admiring-thompson' into develop
2 parents 9763941 + d799fee commit e8e94e4

File tree

7 files changed

+313
-115
lines changed

7 files changed

+313
-115
lines changed

convex-cli/README.md

Lines changed: 225 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,298 @@
11
# Convex CLI
22

3-
## Overview
3+
Command-line interface for the Convex decentralized network. Query state, execute transactions, manage keys, run local test networks, and operate production peers.
44

5-
The `convex-cli` module provides a CLI interface to Convex, including the ability to operate as either a client or peer on the Convex Network
5+
## Quick Start
66

7-
## Usage Examples
7+
```bash
8+
# Check installation
9+
convex --version
810

9-
### List available commands and options
10-
11-
```
11+
# Get help
1212
convex --help
13-
```
14-
15-
### Run a local develop testnet with a GUI
1613

17-
```
14+
# Start a local test network
1815
convex local start
1916
```
2017

21-
### Run the main Convex Desktop GUI application
18+
## Installation
19+
20+
### Prerequisites
2221

22+
Java 21+ is required. Download from [Oracle JDK](https://www.oracle.com/java/technologies/downloads/) or use your package manager.
23+
24+
### Get the JAR
25+
26+
Download `convex.jar` from the [releases page](https://github.com/Convex-Dev/convex/releases) or build from source (see main [README](../README.md)).
27+
28+
### Create a Wrapper Script
29+
30+
**Linux/macOS** - Create `~/bin/convex`:
31+
```bash
32+
#!/bin/bash
33+
java -jar /path/to/convex.jar "$@"
2334
```
24-
convex desktop
35+
Then: `chmod +x ~/bin/convex`
36+
37+
**Windows PowerShell** - Add to your `$PROFILE`:
38+
```powershell
39+
function convex { java -jar C:\path\to\convex.jar $args }
2540
```
2641

27-
### Query the network
42+
## Use Case 1: Local Test Network
2843

29-
This runs the `*balance*` query to get the Convex Coin balance of account `#11`
44+
Spin up a local Convex network for development and testing. This creates a fresh network with genesis accounts you can use immediately.
3045

46+
```bash
47+
# Start local network with GUI
48+
convex local start
49+
50+
# Start without GUI (headless)
51+
convex local start --gui=false
3152
```
32-
convex query -a 11 *balance*
53+
54+
The local network includes:
55+
- A single peer running on localhost:18888
56+
- REST API on localhost:8080
57+
- Pre-funded genesis accounts (#11, #12) for testing
58+
- Faucet enabled for easy account funding
59+
60+
Test your connection:
61+
```bash
62+
convex status --host localhost
3363
```
3464

35-
Queries are free, don't require a signature and you can query for any account on the network.
65+
## Use Case 2: Key Management
3666

37-
## Key Management
67+
Convex uses Ed25519 cryptographic keys for signing transactions. Keys are stored encrypted in a PKCS#12 keystore (default: `~/.convex/keystore.pfx`).
3868

39-
Operating Convex based systems correctly requires cryptographic keys for signing and verification. The CLI helpfully provides a number of useful tools for managing your keys.
69+
### Generate a New Key
4070

41-
### Listing keys
71+
```bash
72+
convex key generate
73+
```
74+
75+
This outputs:
76+
1. A BIP39 mnemonic phrase (12 words) - **back this up securely!**
77+
2. The public key (32-byte hex)
4278

43-
You can get a list of all public keys in the current key store as follows:
79+
You'll be prompted for:
80+
- BIP39 passphrase (used in key derivation)
81+
- Key encryption password (protects the key in storage)
4482

83+
Example output:
4584
```
46-
convex key list
85+
BIP39 mnemonic generated with 12 words:
86+
evidence expand family claw crack dawn name salmon resource leg once curious
87+
Generated key pair with public key: 0x021efb3ff24898dffb30c9c7e490e86b2d0cb7a87c974a51894354532ff4670f
4788
```
4889

49-
By default, keys are store in the `.convex/keystore.pfx` file in the user's home director, but you can override this by either sertting the `CONVEX_KEYSTORE` environment variable or passing the `--keystore` option (works with most CLI commands).
90+
### List Keys
5091

51-
### Generating a key pair
92+
```bash
93+
convex key list
94+
```
5295

53-
To execute transactions or operate peers on Convex you will need a cryptographic Ed25519 key pair.
96+
### Import from Mnemonic
5497

55-
Key pairs are stored in a PKCS #12 key store. By default this is stored in the user's home directory in the location `~/.convex/keystore.pfx`. The keystore encrypts keys so that they cannot be accessed without the correct passwords.
98+
Recover a key from its BIP39 mnemonic:
99+
```bash
100+
convex key import --type=bip39 --text='evidence expand family claw crack dawn name salmon resource leg once curious'
101+
```
56102

57-
To generate a cryptographic key, it is recommended to use the following command:
103+
### Export a Key
58104

59-
```
60-
convex key generate
105+
Export as seed (hex) or mnemonic for backup:
106+
```bash
107+
convex key export --key 021efb --type=seed
108+
convex key export --key 021efb --type=bip39
61109
```
62110

63-
This generates and outputs a BIP39 mnemonic phrase of 12 words consistent with the BIP39 standard. The words will look something like this:
111+
### Environment Variables
64112

113+
Avoid repeated password prompts:
114+
```bash
115+
export CONVEX_KEY=021efb3ff2... # Public key prefix
116+
export CONVEX_KEY_PASSWORD=secret # Key encryption password
117+
export CONVEX_KEYSTORE=~/my-keys.pfx # Custom keystore location
65118
```
66-
evidence expand family claw crack dawn name salmon resource leg once curious
67-
```
68119

69-
You will be also prompted for passwords including:
70-
- A BIP39 passphrase. This is the passphrase that will be used to generate the private key
71-
- A private key encryption password. This protects the new key by encrypting it in the key store
120+
## Use Case 3: Query and Transact
121+
122+
Interact with any Convex network: read state with queries (free), modify state with transactions (requires signed account).
72123

73-
After the key pair is successfully generated, you will be able to use it providing have the private key password.
124+
### Queries (Free, No Signature Required)
74125

75-
If the key is important to you, you will want to be able to recover it even if you permanently lose access to the key store (e.g. if your laptop is stolen, disk drive corrupted etc.). In this case, you SHOULD make sure you securely record the following:
76-
- The BIP39 mnemonic word list
77-
- The BIP39 passphrase
126+
```bash
127+
# Check balance of account #11
128+
convex query "*balance*" -a 11
78129

79-
The command will output a 32 byte hex public key that will look something like this:
130+
# Read any account's balance
131+
convex query "(balance #1234)"
80132

133+
# Get account information
134+
convex account info 11
135+
136+
# Check network status
137+
convex status
81138
```
82-
021efb3ff24898dffb30c9c7e490e86b2d0cb7a87c974a51894354532ff4670f
139+
140+
By default, commands connect to the public network (`peer.convex.live`). For local development:
141+
```bash
142+
convex query "*balance*" -a 11 --host localhost
83143
```
84144

85-
The public key MAY be shared publicly, and is important because it is used to:
86-
- Identify your key pair in the key store
87-
- Validate signatures made with the key pair (e.g. in Convex transactions)
88-
- Create a Convex account protected by the key pair (as the "account key")
89-
90-
### Importing a key pair
145+
### Transactions (Require Key)
146+
147+
Transactions modify state and cost Convex coins. You need:
148+
- An account address (`-a`)
149+
- The account's key (`--key`)
91150

92-
To import a key pair from a BIP39 seed generated previously, you can use the following command:
151+
```bash
152+
# Transfer coins
153+
convex transact "(transfer #1234 1000000)" -a 11 --key 021efb
93154

155+
# Deploy a simple contract
156+
convex transact "(def my-value 42)" -a 11 --key 021efb
157+
158+
# Call a function
159+
convex transact "(call #5678 (my-function arg1 arg2))" -a 11 --key 021efb
94160
```
95-
convex key import --type=bip39 --text='evidence expand family claw crack dawn name salmon resource leg once curious'
161+
162+
### Create an Account
163+
164+
**On local network (faucet enabled):**
165+
```bash
166+
convex account create --faucet --host localhost
167+
```
168+
169+
**On production (requires existing funded account):**
170+
```bash
171+
convex account create -a 11 --key 021efb
96172
```
97173

98-
This will re-import the same key pair that was originally generated, assuming you have the correct BIP39 passphrase. You can confirm this by checking that the public key is the one you expect.
174+
### Fund an Account (Local/Test Networks Only)
99175

176+
```bash
177+
convex account fund -a 1234 1000000000 --host localhost
178+
```
100179

180+
Note: The faucet is disabled on production networks like Protonet.
101181

102-
## Installation
182+
## Use Case 4: Running a Production Peer
103183

104-
### Pre-requisites
184+
Operate a peer node that participates in Convex consensus. Peers validate transactions, maintain state, and serve client requests.
105185

106-
You need a reasonably modern version of Java, specifically 21+. You can get this here:
107-
- [Java JDK from Oracle](https://www.oracle.com/uk/java/technologies/downloads/)
186+
### 1. Generate Peer Key
108187

109-
### .jar file
188+
```bash
189+
convex key generate
190+
# Note the public key, e.g., 7e66429ca...
191+
```
110192

111-
You need the `convex.jar` file. See the main [Convex Readme](../README.md) for details.
193+
### 2. Create Genesis or Join Existing Network
112194

113-
At this point, assuming Java 21+ is correctly installed, you should simple be able to simply execute `java -jar convex.jar` (appending any appropriate CLI arguments).
195+
**Option A: Start a new network (genesis peer):**
196+
```bash
197+
convex peer genesis --peer-key 7e66429ca
198+
```
114199

115-
### Convenience Wrappers
200+
**Option B: Join an existing network:**
116201

117-
It is helpful to have a script, alias or batch file which executes the Java command command for you so you can simply type `convex ....`
202+
First, create your peer's on-chain account and stake:
203+
```bash
204+
# Create peer account on the network
205+
convex transact "(create-peer 0x7e66429ca... 1000000000000)" -a 11 --key 021efb
206+
```
118207

119-
For Windows PowerShell, the following should work:
208+
### 3. Start the Peer
120209

210+
```bash
211+
convex peer start --peer-key 7e66429ca --port 18888
121212
```
122-
# Windows powershell - convex.ps1
123-
function convex {
124-
java -jar C:\path\to\convex.jar $args
125-
}
213+
214+
### Peer Options
215+
216+
```bash
217+
convex peer start \
218+
--peer-key 7e66429ca \
219+
--port 18888 \
220+
--bind 0.0.0.0 \
221+
--api-port 8080 \
222+
--state /var/convex/state
126223
```
127224

128-
Put this in your PowerShell profile (typically `Profile.ps1` in `$home/documents/PowerShell`) and the `convex` command should be available in all future PowerShell sessions.
225+
| Option | Description |
226+
|--------|-------------|
227+
| `--peer-key` | Public key of peer's key pair |
228+
| `--port` | Binary protocol port (default: 18888) |
229+
| `--bind` | Bind address (default: localhost) |
230+
| `--api-port` | REST API port (default: 8080) |
231+
| `--state` | Directory for persistent state |
232+
233+
## Global Options
234+
235+
These options work with most commands:
129236

130-
For Linux and other Unix-like systems:
237+
| Option | Environment Variable | Description |
238+
|--------|---------------------|-------------|
239+
| `--host` | `CONVEX_HOST` | Peer hostname (default: peer.convex.live) |
240+
| `--port` | `CONVEX_PORT` | Peer port (default: 18888) |
241+
| `-a, --address` | `CONVEX_ADDRESS` | Account address |
242+
| `--key` | `CONVEX_KEY` | Public key (prefix) in keystore |
243+
| `--keypass` | `CONVEX_KEY_PASSWORD` | Key encryption password |
244+
| `--keystore` | `CONVEX_KEYSTORE` | Keystore file path |
245+
| `-n, --noninteractive` | - | Disable interactive prompts |
246+
| `-S, --strict-security` | - | Require explicit passwords |
247+
| `-v, --verbose` | `CONVEX_VERBOSE_LEVEL` | Verbosity (0-5) |
248+
249+
## Command Reference
131250

132251
```
133-
#!/bin/bash
134-
java -jar path/to/convex.jar $@
252+
convex
253+
account Account management
254+
create Create a new account
255+
info Get account information
256+
balance Check account balance
257+
fund Request faucet funds (test networks)
258+
259+
key Key management
260+
generate Generate new key pair
261+
list List keys in keystore
262+
import Import key from mnemonic/seed
263+
export Export key
264+
265+
query Execute read-only query
266+
transact Execute transaction
267+
status Check peer/network status
268+
269+
local Local test network
270+
start Start local network
271+
272+
peer Peer operations
273+
start Start a peer node
274+
genesis Create genesis peer
275+
create Create peer on network
276+
277+
desktop Launch GUI application
278+
279+
help Show help for commands
135280
```
136281

137-
Ensure the wrapper is somewhere in your `$PATH`, and you should be good to go!
282+
## Exit Codes
283+
284+
| Code | Meaning |
285+
|------|---------|
286+
| 0 | Success |
287+
| 1 | General error |
288+
| 64 | Usage error (bad arguments) |
289+
| 65 | Data error (invalid input) |
290+
| 68 | No host (cannot connect) |
291+
| 75 | Temporary failure (timeout) |
292+
| 77 | Permission denied |
138293

139294
## License
140295

141-
Copyright 2021-2024 The Convex Foundation and Contributors
296+
Copyright 2021-2025 The Convex Foundation and Contributors
142297

143-
Code in `convex-cli` is provided under the Convex Public License
298+
Code in `convex-cli` is provided under the Convex Public License.

convex-cli/src/main/java/convex/cli/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public int mainExecute(String[] args) {
124124
} catch (ParameterException t) {
125125
informError("ERROR: Unable to parse arguments: " + t.getMessage());
126126
informWarning("For more information on options and commands try 'convex help'.");
127-
return ExitCodes.ERROR;
127+
return ExitCodes.USAGE;
128128
}
129129

130130
if (commandLine.isUsageHelpRequested()) {

0 commit comments

Comments
 (0)