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

# 0G Integration

> ClawMind uses four 0G components in production: Compute, Storage (reports), Storage (memory), and Chain. This page explains how each one is wired into the pipeline.

# 0G Integration

ClawMind's production path is built on the 0G stack: LLM agent inference uses 0G Compute, reports and memory receipts use 0G Storage, and report hashes are anchored on 0G Chain. Local fallbacks exist only for development or misconfigured deployments, and they are surfaced as fallback providers in the API.

<Info>
  All integrations run on **0G Mainnet** (Chain 16661). The active v4 signed registry is `0x24bAAC6720ae5B01A1CC90eCC1C15AFcb903E121`.
</Info>

***

## Component Map

```
User task
   │
   ▼
0G Compute ──────── routes LLM agent inference
   │
   ▼
0G Storage ──────── stores final report JSON → returns 0g:// URI
   │
0G Storage ──────── stores memory index → updated after every run
   │
0G Chain ────────── records hash + score + EIP-712 signature on-chain
```

***

## 0G Compute

ClawMind routes **LLM agent inference** through the 0G Router. Memory retrieval and memory writing use local embeddings plus 0G Storage, while Planner, Researcher, Risk, Architect, Critic, and Final use the router.

| Parameter | Value                                               |
| --------- | --------------------------------------------------- |
| Endpoint  | `https://router-api.0g.ai/v1/chat/completions`      |
| Model     | `deepseek/deepseek-chat-v3-0324`                    |
| Env var   | `ZERO_G_COMPUTE_ENDPOINT`, `ZERO_G_COMPUTE_API_KEY` |

The LLM-backed agents share the same router endpoint. The router handles model dispatch and load balancing across 0G Compute nodes.

**How to verify compute is active:**

```bash theme={null}
curl https://clawmind-puce.vercel.app/api/judge
```

Look for `"integration": { "compute": { "provider": "0G_COMPUTE", "status": "active" } }` in the response. If the provider is `LOCAL_FALLBACK`, the router key or endpoint is missing.

***

## 0G Storage — Reports

After the Final agent produces a report, ClawMind serialises it to JSON and uploads it to 0G Storage. The storage layer returns two identifiers:

* **Root hash** — a content-addressed hash of the report JSON
* **0g:// URI** — a permanent reference in the format `0g://<root-hash>`

Both are shown in the Integrity Panel after every run and are included in the on-chain transaction.

| Parameter | Value                                                                       |
| --------- | --------------------------------------------------------------------------- |
| Env var   | `ZERO_G_STORAGE_ENABLED`, `ZERO_G_STORAGE_PRIVATE_KEY`                      |
| Output    | `provider: "0G_STORAGE"` + `storageUri: "0g://..."` in the decision receipt |

**Retrieve a report by URI:**

```bash theme={null}
curl -X POST https://clawmind-puce.vercel.app/api/report/retrieve \
  -H "Content-Type: application/json" \
  -d '{"storageUriOrRootHash": "0g://your-root-hash"}'
```

**Retrieve a report by root hash:**

```bash theme={null}
curl -X POST https://clawmind-puce.vercel.app/api/report/retrieve \
  -H "Content-Type: application/json" \
  -d '{"storageUriOrRootHash": "0x..."}'
```

<Warning>
  If `ZERO_G_STORAGE_ENABLED` is not set to `true`, reports are returned in-memory only and are not persisted. The on-chain anchoring step will also fail.
</Warning>

***

## 0G Storage — Memory

ClawMind maintains a **persistent memory index** across runs. After the Final agent writes its report, the Memory writer agent compresses the key findings into a structured memory entry and appends it to the index.

On the next run, Step 1 (Memory retrieval) performs semantic search over this index and injects the most relevant past analyses into the Planner's context.

| Parameter | Value                                                |
| --------- | ---------------------------------------------------- |
| Storage   | Same 0G Storage node as reports, separate index file |
| Retrieval | Semantic search over compressed memory entries       |
| Env var   | Same `ZERO_G_STORAGE_PRIVATE_KEY`                    |

**How to verify memory is active:**

```bash theme={null}
curl https://clawmind-puce.vercel.app/api/judge
```

Look for `"memory": { "semanticRetrievalActive": true }` in the response.

The memory index receipt is shown in the UI separately from the report receipt. Both receipts include a `0g://` URI.

***

## 0G Chain

The most critical integrity layer. After the report is stored on 0G Storage, ClawMind submits an on-chain transaction to `AnalysisRegistry.sol` on 0G Chain (Chain 16661).

The transaction records:

| Field            | Description                                           |
| ---------------- | ----------------------------------------------------- |
| `taskHash`       | Hash of the original analysis task                    |
| `reportHash`     | 0G Storage root hash for the report JSON              |
| `score`          | Final numeric score (0–100)                           |
| `recommendation` | `GO` / `INVESTIGATE_MORE` / `NO_GO`                   |
| `storageUri`     | The `0g://` URI from the Storage step                 |
| `timestamp`      | Submission time bound into the signed payload         |
| `operatorSig`    | EIP-712 signature from the authorised operator wallet |

**Contract address:**

```
0x24bAAC6720ae5B01A1CC90eCC1C15AFcb903E121
```

<Card title="View on 0G Explorer" icon="arrow-up-right-from-square" href="https://chainscan.0g.ai/address/0x24bAAC6720ae5B01A1CC90eCC1C15AFcb903E121">
  Inspect all recorded analyses, transaction hashes, and operator signatures.
</Card>

**How EIP-712 signing works:**

The operator wallet signs a typed data payload before every `recordAnalysis` call. This means every on-chain entry is:

1. Tied to a specific operator address
2. Verifiable without trusting the ClawMind backend
3. Detectable if tampered — a changed report hash will not match the stored signature

```bash theme={null}
# Verify operator signature in Judge Mode
curl https://clawmind-puce.vercel.app/api/judge
# Look for "registryMode": "SIGNED_OPERATOR" and "signatureVerified": true
```

**Environment variables:**

```bash theme={null}
ZERO_G_NETWORK=mainnet
ZERO_G_ANALYSIS_REGISTRY_ADDRESS=0x24bAAC6720ae5B01A1CC90eCC1C15AFcb903E121
ZERO_G_ALLOW_LEGACY_REGISTRY_WRITES=false
```

<Warning>
  `ZERO_G_ALLOW_LEGACY_REGISTRY_WRITES` must be `false` in production. Setting it to `true` bypasses EIP-712 signing and produces unauthenticated writes.
</Warning>

<Note>
  Earlier v3 registry deployments are historical. The public app, `/stats`, `/api/judge`, `/analysis`, and the MCP flow all use the v4 signed registry above.
</Note>

***

## OpenClaw Manifest

ClawMind exposes an **OpenClaw manifest** — a machine-readable description of the agent pipeline, its artifacts, and its security policies. This makes ClawMind composable with other agent systems in the 0G ecosystem.

```bash theme={null}
# YAML format
curl https://clawmind-puce.vercel.app/api/openclaw/manifest

# JSON format with live 0G evidence
curl https://clawmind-puce.vercel.app/api/openclaw/manifest?format=json
```

The JSON format includes live evidence fields: the current contract address, pipeline step count, memory status, and recent analyses — all pulled at request time.

The manifest is defined in `openclaw.yaml` at the root of the repository.

***

## Full Verification Checklist

Run these checks to confirm all four 0G integrations are live:

| Check                     | Command / Location                                                         | Expected                                                     |
| ------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------ |
| Compute is active         | `GET /api/judge` → `integration.compute.status`                            | `active`                                                     |
| Pipeline has 8 steps      | `GET /api/judge` → `integration.openClaw.pipelineSteps`                    | `8`                                                          |
| Memory is active          | `GET /api/judge` → `memory.semanticRetrievalActive`                        | `true`                                                       |
| Contract address matches  | `GET /api/judge` → `integration.onChain.contractAddress` vs `.env.example` | Identical                                                    |
| Live stats are public     | Open `/stats`                                                              | Signed registry, memory, critic, and MCP metrics are visible |
| Reports are persisted     | Run analysis → decision receipt                                            | `provider: "0G_STORAGE"` + `0g://` URI                       |
| On-chain anchoring works  | Run analysis → open tx from on-chain receipt                               | Transaction visible on 0G Explorer                           |
| Operator is authenticated | On-chain receipt or Judge Mode                                             | `SIGNED_OPERATOR` + valid signature                          |
| Integrity is checkable    | Compare UI hash with on-chain hash                                         | Hashes match                                                 |

***

## Deploying the Registry

If you are self-hosting ClawMind and need to deploy your own `AnalysisRegistry.sol`:

```bash theme={null}
# Install Foundry first, then:
git submodule update --init --recursive
node scripts/deploy-registry.mjs
```

The deployer wallet is automatically authorised as the first EIP-712 operator. Replace `ZERO_G_ANALYSIS_REGISTRY_ADDRESS` in your `.env` with the deployed address.
