neo-cli 1.0.0

Command-line interface for the NeoRust SDK
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# Neo CLI Documentation

## Table of Contents

1. [Introduction]#introduction
2. [Installation]#installation
3. [Configuration]#configuration
4. [Command Reference]#command-reference
   - [Wallet Commands]#wallet-commands
   - [Blockchain Commands]#blockchain-commands
   - [Network Commands]#network-commands
   - [Contract Commands]#contract-commands
   - [DeFi Commands]#defi-commands
5. [Advanced Usage]#advanced-usage
6. [Troubleshooting]#troubleshooting
7. [API Integration]#api-integration

## Introduction

Neo CLI is a comprehensive command-line tool for interacting with the Neo blockchain ecosystem. Built on the NeoRust SDK, it provides a user-friendly interface for performing a wide range of operations on the Neo blockchain.

### Key Features

- Complete wallet management functionality
- Blockchain query and monitoring capabilities
- Smart contract deployment and interaction
- Network configuration and management
- DeFi platform integration
- Secure key handling and transaction signing

## Installation

### Prerequisites

- Rust 1.63 or higher
- Cargo package manager
- (Optional) Git for cloning the repository

### Installation Methods

#### From Source

```bash
# Clone the repository
git clone https://github.com/r3-network/neo-rust.git
cd neo-rust

# Build the CLI tool
cargo build --release -p neo-cli

# Add to your PATH (optional)
cp target/release/neo-cli /usr/local/bin/
```

#### Using Cargo

```bash
cargo install neo-cli
```

## Configuration

Neo CLI requires a configuration file to store settings such as:

- RPC endpoint URLs
- Default network (MainNet, TestNet, or custom)
- Default wallet paths
- Logging preferences

### Initializing Configuration

```bash
neo-cli init [--path /custom/path/config.json]
```

Without specifying a path, the configuration file will be created in your system's default configuration directory.

### Configuration File Structure

The configuration file uses JSON format:

```json
{
  "network": {
    "default": "mainnet",
    "rpc": {
      "mainnet": "http://seed1.neo.org:10332",
      "testnet": "http://seed1.neo.org:20332"
    }
  },
  "wallet": {
    "default_path": "/path/to/wallets"
  },
  "logging": {
    "level": "info"
  }
}
```

You can edit this file manually or use the CLI to update settings.

## Command Reference

### Global Options

These options can be used with any command:

- `--config`: Specify a custom configuration file path
- `--verbose`: Enable verbose output
- `--help`: Display help information
- `--version`: Display version information

### Wallet Commands

#### Create a New Wallet

```bash
neo-cli wallet create [--name <NAME>] [--path <PATH>] [--password <PASSWORD>]
```

Options:
- `--name`: Name of the wallet (default: "wallet")
- `--path`: Custom path to save the wallet file
- `--password`: Password to encrypt the wallet (will prompt if not provided)

#### Open Wallet

```bash
neo-cli wallet open [--name <NAME>] [--path <PATH>]
```

Options:
- `--name`: Name of the wallet
- `--path`: Path to the wallet file

#### Check Wallet Balance

```bash
neo-cli wallet balance [--address <ADDRESS>] [--name <NAME>] [--path <PATH>]
```

Options:
- `--address`: Specific address to check (optional)
- `--name`: Name of the wallet
- `--path`: Path to the wallet file

#### Transfer Assets

```bash
neo-cli wallet transfer --to <ADDRESS> --asset <ASSET> --amount <AMOUNT> [--from <ADDRESS>] [--name <NAME>] [--path <PATH>]
```

Options:
- `--to`: Recipient address
- `--asset`: Asset identifier (NEO, GAS, or script hash)
- `--amount`: Amount to transfer
- `--from`: Sender address (optional, will use default if not specified)
- `--name`: Name of the wallet
- `--path`: Path to the wallet file

#### Export Wallet

```bash
neo-cli wallet export [--format <FORMAT>] [--name <NAME>] [--path <PATH>] [--output <OUTPUT_PATH>]
```

Options:
- `--format`: Export format (NEP6, WIF, etc.)
- `--name`: Name of the wallet
- `--path`: Path to the wallet file
- `--output`: Path to save the exported wallet

#### Import Wallet

```bash
neo-cli wallet import --input <INPUT_PATH> [--format <FORMAT>] [--name <NAME>] [--path <PATH>]
```

Options:
- `--input`: Path to the wallet file to import
- `--format`: Import format (NEP6, WIF, etc.)
- `--name`: Name to save the wallet as
- `--path`: Path to save the imported wallet

### Blockchain Commands

#### Get Blockchain Information

```bash
neo-cli blockchain info
```

Displays general information about the blockchain, including height, version, and consensus nodes.

#### Get Current Block Height

```bash
neo-cli blockchain height
```

Returns the current block height of the connected network.

#### Get Block Information

```bash
neo-cli blockchain block [--hash <HASH>] [--index <INDEX>]
```

Options:
- `--hash`: Block hash
- `--index`: Block index/height

#### Get Transaction Information

```bash
neo-cli blockchain tx --hash <HASH>
```

Options:
- `--hash`: Transaction hash

#### Get Asset Information

```bash
neo-cli blockchain asset --id <ASSET_ID>
```

Options:
- `--id`: Asset identifier (script hash)

### Network Commands

#### Check Network Status

```bash
neo-cli network status
```

Displays the status of the connected network, including node count and recent blocks.

#### List Connected Nodes

```bash
neo-cli network nodes
```

Lists all connected nodes and their information.

#### Switch Network

```bash
neo-cli network switch --network <NETWORK>
```

Options:
- `--network`: Network to switch to (mainnet, testnet, private)

### Contract Commands

#### Deploy Smart Contract

```bash
neo-cli contract deploy --path <NEF_PATH> --manifest <MANIFEST_PATH> [--wallet <WALLET_PATH>] [--account <ACCOUNT>]
```

Options:
- `--path`: Path to the NEF file
- `--manifest`: Path to the manifest file
- `--wallet`: Path to the wallet file
- `--account`: Account to pay for deployment

#### Invoke Contract Method

```bash
neo-cli contract invoke --contract <CONTRACT_HASH> --method <METHOD_NAME> [--params <PARAMS>] [--wallet <WALLET_PATH>] [--account <ACCOUNT>]
```

Options:
- `--contract`: Contract script hash
- `--method`: Name of the method to invoke
- `--params`: Parameters for the method (JSON format)
- `--wallet`: Path to the wallet file
- `--account`: Account to pay for the invocation

#### Get Contract Information

```bash
neo-cli contract info --contract <CONTRACT_HASH>
```

Options:
- `--contract`: Contract script hash

#### Query Contract Storage

```bash
neo-cli contract storage --contract <CONTRACT_HASH> [--key <KEY>] [--prefix <PREFIX>]
```

Options:
- `--contract`: Contract script hash
- `--key`: Specific key to query
- `--prefix`: Key prefix for querying multiple keys

### DeFi Commands

#### Perform Token Swap

```bash
neo-cli defi swap --from <TOKEN> --to <TOKEN> --amount <AMOUNT> [--max-slippage <SLIPPAGE>] [--wallet <WALLET_PATH>]
```

Options:
- `--from`: Source token (NEO, GAS, or script hash)
- `--to`: Target token (NEO, GAS, or script hash)
- `--amount`: Amount to swap
- `--max-slippage`: Maximum acceptable slippage percentage
- `--wallet`: Path to the wallet file

#### Stake Tokens

```bash
neo-cli defi stake --token <TOKEN> --amount <AMOUNT> --platform <PLATFORM> [--duration <DURATION>] [--wallet <WALLET_PATH>]
```

Options:
- `--token`: Token to stake
- `--amount`: Amount to stake
- `--platform`: Staking platform
- `--duration`: Staking duration in days
- `--wallet`: Path to the wallet file

#### Check Yield Farming Positions

```bash
neo-cli defi yield [--wallet <WALLET_PATH>] [--platform <PLATFORM>]
```

Options:
- `--wallet`: Path to the wallet file
- `--platform`: Specific platform to check

#### List Liquidity Pools

```bash
neo-cli defi pools [--platform <PLATFORM>]
```

Options:
- `--platform`: Specific platform to check

## Advanced Usage

### Working with Multi-Signature Wallets

```bash
neo-cli wallet create-multisig --min-signatures <COUNT> --pubkeys <PUBKEY1,PUBKEY2,...> [--name <NAME>]
```

### Batch Operations

For performing operations in batch mode, you can use JSON input files:

```bash
neo-cli batch --input <BATCH_FILE_PATH>
```

### Scripting Support

Neo CLI can be used in shell scripts. All commands return appropriate exit codes and structured output that can be parsed by other tools.

## Troubleshooting

### Common Issues

- **Connection problems**: Verify network settings in the configuration file
- **Transaction failures**: Check account balance and network fees
- **Wallet access issues**: Ensure the wallet password is correct and the file is not corrupted

### Logs

Logs are stored in the system's temporary directory. You can increase verbosity with the `--verbose` flag.

### Getting Help

For additional help, use the `--help` flag with any command or visit the project's GitHub repository.

## API Integration

Neo CLI can be used as a library in other Rust applications:

```rust
use neo_cli::commands::wallet;

async fn example() {
    let args = wallet::WalletArgs::Create {
        name: Some("my-wallet".to_string()),
        path: None,
        password: None,
    };
    
    let mut state = wallet::CliState::default();
    wallet::handle_wallet_command(args, &mut state).await.unwrap();
}
```

For more information on API integration, see the [API documentation](https://docs.rs/neo-cli).