# Starting the Daemon and Wallet as RPC Server

The Lethean wallet CLI (`lethean-wallet-cli` / `lethean-testnet-wallet-cli`) can run as an RPC server, controlled via HTTP JSON-RPC calls. This is the standard setup for exchanges, payment processors, and automated services.

### 1. Start the daemon

```bash
# Mainnet
./lethean-chain-node --data-dir ./chain-data

# Testnet
./lethean-testnet-chain-node --data-dir ./testnet-data
```

### 2. Create a wallet (first time only)

```bash
./lethean-wallet-cli --generate-new-wallet /path/to/exchange-wallet \
  --password "STRONG_PASSWORD" \
  --daemon-address 127.0.0.1:36941
```

Save the 24-word seed phrase securely. The wallet address starts with `iTHN`.

### 3. Start wallet in RPC mode

```bash
./lethean-wallet-cli \
  --wallet-file /path/to/exchange-wallet \
  --password "STRONG_PASSWORD" \
  --rpc-bind-ip 127.0.0.1 \
  --rpc-bind-port 36944 \
  --daemon-address 127.0.0.1:36941 \
  --log-file wallet-rpc.log
```

### 4. Test the connection

```bash
# Get wallet address
curl -X POST http://127.0.0.1:36944/json_rpc \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":"0","method":"getaddress"}'

# Get balance
curl -X POST http://127.0.0.1:36944/json_rpc \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":"0","method":"getbalance"}'
```

### Port reference

| Service | Mainnet | Testnet |
|---------|---------|---------|
| Daemon RPC | 36941 | 46941 |
| Daemon P2P | 36942 | 46942 |
| Wallet RPC | 36944 (custom) | 46944 (custom) |

### Units

All amounts and balances are unsigned integers in **atomic units**. One LTHN = 10^12 atomic units.

| Human | Atomic |
|-------|--------|
| 1 LTHN | 1000000000000 |
| 0.5 LTHN | 500000000000 |
| 0.01 LTHN (min fee) | 10000000000 |

### Verified against testnet

These commands have been tested against the live Lethean testnet at height 10,676. The wallet RPC responds to `getaddress`, `getbalance`, `get_wallet_info`, `make_integrated_address`, and `get_bare_outs_stats`.
