# Environment Variables

Complete reference of all environment variables across NCN Network v2 components.

***

## Gateway Node

### Required

| Variable                     | Description                       | Example                  |
| ---------------------------- | --------------------------------- | ------------------------ |
| `GATEWAY_WALLET_PRIVATE_KEY` | Gateway wallet private key        | `0xabcd...`              |
| `RPC_URL`                    | Blockchain RPC endpoint           | `http://127.0.0.1:8545`  |
| `CONTRACT_ADDRESS`           | InferencePayment contract address | `0x4361...`              |
| `REGISTRY_GRPC_ADDR`         | P2P Registry gRPC address         | `http://127.0.0.1:50050` |

### Optional

| Variable                      | Default           | Description                       |
| ----------------------------- | ----------------- | --------------------------------- |
| `GATEWAY_WALLET_ADDRESS`      | Derived           | Wallet address (derived from key) |
| `GRPC_ADDR`                   | `127.0.0.1:50051` | gRPC listen address               |
| `HTTP_ADDR`                   | `127.0.0.1:8080`  | HTTP listen address               |
| `WS_ADDR`                     | `127.0.0.1:9000`  | WebSocket listen address          |
| `SUBNET_ID`                   | `1`               | Gateway's subnet ID               |
| `NETWORK`                     | `forknet`         | Network name                      |
| `GAS_LIMIT`                   | `500000`          | Default gas limit                 |
| `GAS_PRICE_MULTIPLIER`        | `1.1`             | Gas price multiplier              |
| `REQUIRED_CONFIRMATIONS`      | `1`               | Required tx confirmations         |
| `CONFIRMATION_TIMEOUT_SECS`   | `300`             | Confirmation timeout              |
| `ENABLE_PAYMENT_VERIFICATION` | `true`            | Enable payment verification       |
| `REQUIRE_PAYMENT`             | `false`           | Require payment for requests      |

***

## Compute Node

### Required

| Variable       | Description                  | Example                  |
| -------------- | ---------------------------- | ------------------------ |
| `GATEWAY_ADDR` | Gateway address (or CLI arg) | `http://127.0.0.1:50051` |

### Optional

| Variable                    | Default            | Description                                      |
| --------------------------- | ------------------ | ------------------------------------------------ |
| `COMPUTE_NODE_PRIVATE_KEY`  | Auto-generated     | Node wallet private key                          |
| `NODE_WALLET_ADDRESS`       | Derived            | Node wallet address                              |
| `MODEL_PATH`                | `./models`         | Model files directory                            |
| `SANDBOX_MODE`              | `strict`           | Sandbox mode: `strict`, `permissive`, `disabled` |
| `EXECUTION_TIMEOUT_SECS`    | `300`              | Max execution time (seconds)                     |
| `MAX_MEMORY_MB`             | `4096`             | Max memory per execution (MB)                    |
| `MAX_CPU_CORES`             | All                | Max CPU cores per execution                      |
| `ENABLE_EXECUTION_FALLBACK` | `false`            | Enable fallback execution                        |
| `REQUIRE_PAYMENT`           | `false`            | Require payment validation                       |
| `PYTHON_EXECUTOR_PATH`      | `python_executors` | Path to Python executors                         |
| `PYTHON_PATH`               | `python3`          | Python interpreter path                          |
| `PYTHON_VENV_PATH`          | None               | Python virtual environment                       |

### Sandbox-specific

| Variable                | Default | Description              |
| ----------------------- | ------- | ------------------------ |
| `SANDBOX_ALLOW_NETWORK` | `false` | Allow network in sandbox |
| `SANDBOX_ALLOWED_PATHS` | `/tmp`  | Additional allowed paths |
| `SANDBOX_MAX_PROCESSES` | `10`    | Max processes in sandbox |
| `SANDBOX_MAX_FDS`       | `1024`  | Max file descriptors     |

***

## P2P Registry Node

### Required

| Variable | Description       | Example |
| -------- | ----------------- | ------- |
| None     | All have defaults | -       |

### Optional

| Variable                       | Default                 | Description                   |
| ------------------------------ | ----------------------- | ----------------------------- |
| `P2P_LISTEN_ADDR`              | `/ip4/0.0.0.0/tcp/8828` | P2P listen address            |
| `GRPC_LISTEN_ADDR`             | `127.0.0.1:50050`       | gRPC listen address           |
| `VALIDATOR_PRIVATE_KEY`        | Auto-generated          | Validator signing key         |
| `VALIDATOR_SYNC_ENABLED`       | `true`                  | Enable blockchain sync        |
| `VALIDATOR_SYNC_INTERVAL`      | `60`                    | Sync interval (seconds)       |
| `VALIDATOR_SYNC_ACTIVE_ONLY`   | `false`                 | Sync only active validators   |
| `VALIDATOR_REGISTRY_CONTRACT`  | None                    | On-chain validator registry   |
| `FORKNET_RPC_URL`              | None                    | Blockchain RPC URL            |
| `CHAIN_ID`                     | `828`                   | Blockchain chain ID           |
| `MIN_VALIDATORS_FOR_CONSENSUS` | `3`                     | Minimum validators for M-of-N |
| `MAX_VALIDATORS_TO_SELECT`     | `5`                     | Maximum validators to select  |
| `MIN_REPUTATION_THRESHOLD`     | `20`                    | Minimum validator reputation  |

***

## Test Client

### Required

| Variable | Description              | Example |
| -------- | ------------------------ | ------- |
| None     | All configurable via CLI | -       |

### Optional

| Variable             | Default                  | Description               |
| -------------------- | ------------------------ | ------------------------- |
| `GATEWAY_ADDR`       | `http://127.0.0.1:50051` | Gateway gRPC address      |
| `CLIENT_PRIVATE_KEY` | None                     | Client wallet private key |
| `NETWORK`            | `local`                  | Network name              |

***

## Smart Contracts (Foundry)

### Deployment

| Variable            | Description          | Example                 |
| ------------------- | -------------------- | ----------------------- |
| `PRIVATE_KEY`       | Deployer private key | `0xabcd...`             |
| `RPC_URL`           | RPC endpoint         | `http://127.0.0.1:8545` |
| `ETHERSCAN_API_KEY` | For verification     | `ABC123...`             |

***

## Logging

### All Components

| Variable         | Default | Description                                            |
| ---------------- | ------- | ------------------------------------------------------ |
| `RUST_LOG`       | `info`  | Log level filter                                       |
| `RUST_BACKTRACE` | `0`     | Enable backtraces (`1` for basic, `full` for detailed) |

### Log Level Examples

```bash
# Basic info
export RUST_LOG=info

# Debug all
export RUST_LOG=debug

# Debug specific component
export RUST_LOG=gateway_node=debug,compute_node=info

# Trace specific module
export RUST_LOG=gateway_node::payment=trace

# Multiple filters
export RUST_LOG=info,gateway_node=debug,libp2p=warn
```

***

## Docker Environment

### Docker Compose Variables

Create `.env` file in project root:

```bash
# Blockchain
RPC_URL=http://localhost:8545
CONTRACT_ADDRESS=0x4361115359E5C0a25c9b2f8Bb71184F010b768ea
CHAIN_ID=828

# Gateway
GATEWAY_PRIVATE_KEY=0x...
GATEWAY_WALLET_ADDRESS=0x...

# Compute
COMPUTE_PRIVATE_KEY=0x...
SANDBOX_MODE=disabled

# Registry
VALIDATOR_PRIVATE_KEY=0x...
VALIDATOR_SYNC_ENABLED=true

# General
RUST_LOG=info
```

***

## Security Notes

### Sensitive Variables

**NEVER commit these to version control:**

* `*_PRIVATE_KEY`
* `*_SECRET`
* API keys

### Best Practices

```bash
# Use environment variables
export GATEWAY_WALLET_PRIVATE_KEY="$SECRET_FROM_VAULT"

# Or use .env file (add to .gitignore)
echo ".env" >> .gitignore

# Use secrets manager in production
# (AWS Secrets Manager, HashiCorp Vault, etc.)
```

***

## Quick Setup Templates

### Development

```bash
# Development mode - no payment, no sandbox
export RUST_LOG=debug
export REQUIRE_PAYMENT=false
export SANDBOX_MODE=disabled
export ENABLE_EXECUTION_FALLBACK=true
```

### Testing

```bash
# Testing mode - permissive sandbox
export RUST_LOG=info
export REQUIRE_PAYMENT=false
export SANDBOX_MODE=permissive
export ENABLE_EXECUTION_FALLBACK=true
```

### Production

```bash
# Production mode - strict security
export RUST_LOG=info
export REQUIRE_PAYMENT=true
export SANDBOX_MODE=strict
export ENABLE_EXECUTION_FALLBACK=false
export REQUIRED_CONFIRMATIONS=12
```

***

## Variable Priority

Configuration priority (highest to lowest):

1. Command line arguments
2. Environment variables
3. `.env` file
4. Default values

```bash
# CLI overrides environment variable
export GRPC_ADDR=127.0.0.1:50051
cargo run --bin gateway_node -- --grpc-addr 0.0.0.0:50051
# Uses 0.0.0.0:50051
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.neurochain.ai/nc/neurochainai-guides/configuration/environment-vars.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
