> ## Documentation Index
> Fetch the complete documentation index at: https://docs.li.fi/llms.txt
> Use this file to discover all available pages before exploring further.

# Examples

> Output modes, exit codes, and end-to-end workflow examples for the LI.FI CLI

## Output Modes

The CLI auto-detects your terminal and adjusts output format accordingly.

| Mode    | Trigger                       | Behaviour                          |
| ------- | ----------------------------- | ---------------------------------- |
| Human   | Default (TTY detected)        | Coloured tables, formatted amounts |
| Machine | `--json` flag or non-TTY pipe | Raw JSON, stable schema, no colour |

### Pipe-Friendly Output

The CLI auto-detects non-TTY environments and switches to JSON:

```bash theme={"system"}
# Auto-detects non-TTY — outputs JSON
lifi chains | jq '.chains[].name'
```

### Force JSON in Terminal

```bash theme={"system"}
lifi chains --json
```

### Disable Colour

```bash theme={"system"}
lifi chains --no-color
```

### Verbose Errors

Enable stack traces for debugging:

```bash theme={"system"}
lifi quote --from 1 --to 42161 --verbose
```

## Exit Codes

| Code | Meaning                              |
| ---- | ------------------------------------ |
| 0    | Success                              |
| 1    | General error                        |
| 2    | Invalid arguments / usage            |
| 3    | Authentication error                 |
| 4    | API error (rate limit, server error) |
| 5    | Network error (unreachable)          |

## End-to-End Workflow: Cross-Chain Swap

This example walks through a complete cross-chain USDC transfer from Ethereum to Base.

### Step 1: Find Chain IDs

```bash theme={"system"}
lifi chains --type EVM
```

### Step 2: Look Up Token Address

```bash theme={"system"}
lifi token 1 USDC
```

### Step 3: Get Best Quote

```bash theme={"system"}
lifi quote \
  --from 1 --to 8453 \
  --from-token USDC --to-token USDC \
  --amount 1000000000 \
  --from-address 0xYOUR_ADDRESS
```

The response includes a `transactionRequest` object ready for signing.

### Step 4: Approve and Sign (External)

Use your wallet to:

1. Approve the token spend if needed
2. Sign and broadcast the `transactionRequest` from the quote

### Step 5: Track Progress

```bash theme={"system"}
lifi status 0xTX_HASH --watch
```

The `--watch` flag polls until the transfer completes or fails.

## Scripting Example

Combine commands in a shell script:

```bash theme={"system"}
#!/bin/bash

# Get the cheapest route for 1000 USDC from Ethereum to Base
QUOTE=$(lifi quote \
  --from 1 --to 8453 \
  --from-token USDC --to-token USDC \
  --amount 1000000000 \
  --from-address "$WALLET_ADDRESS" \
  --json)

# Extract estimated output
echo "$QUOTE" | jq '.estimate.toAmountUSD'

# Extract transaction request for external signing
echo "$QUOTE" | jq '.transactionRequest'
```
