> For the complete documentation index, see [llms.txt](https://docs.neurochain.ai/nc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.neurochain.ai/nc/neurochainai-guides/components/test-client.md).

# Test Client

The Test Client is an example application for testing NCN Network functionality, including the complete inference and payment flow.

***

## Overview

```
┌─────────────────────────────────────────────────────────────────────────────┐
│                            Test Client                                       │
│                                                                             │
│   ┌───────────────────────────────────────────────────────────────────┐     │
│   │                    Command Line Interface                          │     │
│   │   --gateway-addr, --wallet-key, --model-path, --text, etc.       │     │
│   └───────────────────────────────────────────────────────────────────┘     │
│                                                                             │
│   ┌───────────────────────────────────────────────────────────────────┐     │
│   │                      Inference Pipeline                            │     │
│   │   1. Submit request                                                │     │
│   │   2. Handle payment                                                │     │
│   │   3. Wait for result                                               │     │
│   │   4. Verify and display                                            │     │
│   └───────────────────────────────────────────────────────────────────┘     │
│                                                                             │
│   ┌───────────────────────────────────────────────────────────────────┐     │
│   │                     Payment Manager                                │     │
│   │   • Wallet management                                              │     │
│   │   • Balance checking                                               │     │
│   │   • Transaction submission                                         │     │
│   │   • Confirmation waiting                                           │     │
│   └───────────────────────────────────────────────────────────────────┘     │
│                                                                             │
│   Connections:                                                              │
│   ├── Gateway (gRPC) ────────────────────▶ :50051                          │
│   └── Blockchain (JSON-RPC) ─────────────▶ RPC_URL                         │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘
```

***

## Features

* **Complete Payment Flow**: Handles preprocessing, payment, and completion
* **Multi-Network Support**: Local, forknet, testnet, mainnet
* **Bark Pipeline**: Text-to-audio pipeline testing
* **Dry Run Mode**: Test without actual payments
* **Detailed Logging**: Visual progress indicators

***

## Quick Start

### Build

```bash
cargo build --release -p test_client
```

### Basic Usage

```bash
# Simple test (no payment)
cargo run --release --bin test_client

# With payment
cargo run --release --bin test_client -- \
  --wallet-key 0xYOUR_PRIVATE_KEY \
  --network forknet
```

### Full Options

```bash
cargo run --release --bin test_client -- \
  --gateway-addr http://127.0.0.1:50051 \
  --wallet-key 0xYOUR_PRIVATE_KEY \
  --network forknet \
  --rpc-url http://127.0.0.1:8545 \
  --semantic-model-path ./models/semantic.pt \
  --coarse-model-path ./models/coarse.pt \
  --fine-model-path ./models/fine.pt \
  --text "Hello, this is a test"
```

***

## Command Line Options

| Option                  | Required | Default                  | Description               |
| ----------------------- | -------- | ------------------------ | ------------------------- |
| `--gateway-addr`        | No       | `http://127.0.0.1:50051` | Gateway gRPC address      |
| `--wallet-key`          | No\*     | -                        | Client wallet private key |
| `--network`             | No       | `local`                  | Network name              |
| `--rpc-url`             | No       | Auto                     | Blockchain RPC URL        |
| `--contract-address`    | No       | Auto                     | Payment contract address  |
| `--semantic-model-path` | No       | -                        | Semantic model path       |
| `--coarse-model-path`   | No       | -                        | Coarse model path         |
| `--fine-model-path`     | No       | -                        | Fine model path           |
| `--text`                | No       | Default                  | Text input for TTS        |
| `--dry-run`             | No       | `false`                  | Skip actual payment       |

\*Required if network requires payment

***

## Output Examples

### Successful Run

```
╔════════════════════════════════════════╗
║  NCN Network Test Client               ║
╚════════════════════════════════════════╝

Connecting to Gateway at http://127.0.0.1:50051...
✓ Connected to Gateway

╔════════════════════════════════════════╗
║  Step: Text to Semantic                ║
╚════════════════════════════════════════╝

📤 Submitting inference request...
Task ID: req-abc123
Status: queued

💰 Payment Information:
┌─────────────────────────────────────────────┐
│ Payment Breakdown                           │
├─────────────────────────────────────────────┤
│ Compute Price:      1000000000000000000 wei │
│ Gateway Gas:         100000000000000000 wei │
│ Validator Reward:     50000000000000000 wei │
│ Treasury Fee:         50000000000000000 wei │
├─────────────────────────────────────────────┤
│ Total:              1200000000000000000 wei │
└─────────────────────────────────────────────┘
  ≈ 1.200000 ETH

💼 Checking balance...
✓ Balance: 10.0 ETH (sufficient)

💸 Sending payment transaction...
✓ Transaction sent: 0x1234...

⏳ Waiting for confirmation...
✓ Confirmed in block 12345678

📨 Subscribing to results...
✓ Received result in 1.25s

Output: [semantic tokens data]

╔════════════════════════════════════════╗
║  Step: Semantic to Coarse              ║
╚════════════════════════════════════════╝
...

✅ All steps completed successfully!
Total time: 5.3s
Output saved to: output.wav
```

### Dry Run Mode

```
╔════════════════════════════════════════╗
║  NCN Network Test Client (DRY RUN)     ║
╚════════════════════════════════════════╝

⚠️  Dry run mode - no actual payments will be made

📤 Submitting inference request...
Task ID: req-xyz789

💰 Would pay: 1.2 ETH
   (skipping actual payment in dry run mode)

📨 Subscribing to results...
...
```

***

## Configuration

### Environment Variables

```bash
# Optional environment configuration
export GATEWAY_ADDR=http://127.0.0.1:50051
export CLIENT_PRIVATE_KEY=0x...
export NETWORK=forknet
export RPC_URL=http://127.0.0.1:8545
```

### Network Configurations

| Network   | RPC URL                 | Notes               |
| --------- | ----------------------- | ------------------- |
| `local`   | `http://127.0.0.1:8545` | Local Anvil/Hardhat |
| `forknet` | `http://127.0.0.1:8545` | NCN Forknet         |
| `sepolia` | Infura/Alchemy URL      | Ethereum testnet    |
| `mainnet` | Infura/Alchemy URL      | Ethereum mainnet    |

***

## Payment Flow

### Without Payment (Development)

```
1. Submit request → Gateway
2. Gateway queues task
3. Compute node executes
4. Result returned
```

### With Payment

```
1. Submit request → Gateway
2. Receive payment info
3. Submit blockchain transaction
4. Wait for confirmation
5. Confirm with gateway
6. Compute node executes
7. Result returned
8. Payment distributed
```

***

## Bark Pipeline

The test client supports the full Bark text-to-audio pipeline:

### Pipeline Stages

```
Text → Semantic → Coarse → Fine → Audio
         │          │        │
         ▼          ▼        ▼
    Semantic    Coarse    Fine
     Tokens     Tokens   Tokens
```

### Usage

```bash
cargo run --bin test_client -- \
  --semantic-model-path ./models/bark_semantic_model.pt \
  --coarse-model-path ./models/bark_coarse_model.pt \
  --fine-model-path ./models/bark_fine_model.pt \
  --text "Hello, this is NCN Network speaking."
```

***

## Troubleshooting

### Common Issues

**"Connection refused"**

* Ensure Gateway is running
* Check `--gateway-addr` is correct

**"Insufficient funds"**

* Check wallet balance
* Use faucet to get testnet tokens
* Use `--dry-run` for testing

**"Model not found"**

* Verify model paths are correct
* Ensure compute node has models

**"Payment verification failed"**

* Wait for more confirmations
* Check RPC URL connectivity
* Verify contract address

***

## Related Documentation

* [Usage Examples](https://github.com/NeuroChainAi/docs-guides/blob/main/components/test-client/usage.md) - More detailed examples
* [Payment Integration](https://github.com/NeuroChainAi/docs-guides/blob/main/guides/clients/payment-integration.md) - Payment details
* [Gateway gRPC API](https://github.com/NeuroChainAi/docs-guides/blob/main/api-reference/gateway-grpc.md) - API reference
