# 快速开始

## Ceramic 基本概念

这是关于 Ceramic 基本概念的简单介绍。您可以通过使用 Ceramic CLI 学习基础知识。

## 设置

### **预备条件**

Ceramic 需要 Node.js v16 和 npm v6。虽然 npm v7 并未官方支持，但你可能还是能让它运行起来。你需要全局安装 node-pre-gyp 包。在 IPFS 依赖的 node-webrtc 升级之前，这是必须的。

```Plain
npm install -g node-pre-gyp
```

### **安装 Ceramic**

打开控制台，使用 npm 安装 CLI：

```Plain
npm install --global @ceramicnetwork/cli @glazed/cli
```

现在，Ceramic CLI 可以通过 `ceramic` 访问，Glaze CLI 可以通过 `glaze` 访问。运行 `ceramic help` 和 `glaze help` 来列出可用的命令。<br>

### **启动 Ceramic**

启动一个与 Clay Testnet 连接的本地 Ceramic 节点，访问地址：[https://localhost:7007：](https://ceramic-zhong-wen-wen-dang.gitbook.io/ceramic-zhong-wen-wen-dang/ceramic-ji-ben-jie-shao/https:/localhost:7007：)

```Plain
ceramic daemon
```

<br>

### **创建账户**

Ceramic 交易必须由一个账户（DID）签名。Glaze CLI 可以为你创建一个 DID，只需生成一个 32 字节的随机种子：

```Plain
glaze did:create
```

你的输出应该类似于这样，`...` 用于简洁：

```Plain
✔ Created DID did:key:z6Mk... with seed ab...f0
```

然后，可以在运行其他命令时使用这个种子：

```Plain
glaze [command] --key=ab...f0
DID_KEY=ab...f0 glaze [command]
```

注意：输入 `--key` 时，应该是你的编码种子，而不是 `did:key` 本身。<br>

## Streams 数据流

Ceramic 的使用取决于你正在与之交互的特定类型的 streams，因为它们各自有自己的 API。在这个例子中，Glaze CLI 与 tile documents 交互，streams 存储可变的 JSON。<br>

### **创建**

使用你的账户创建一个新的 tile document：

```Plain
glaze tile:create --key ab...f0 --content '{"Foo":"Bar"}'
```

更多选项 `--metadata`: 设置流的元数据 运行 `glaze tile:create -h` 查看所有可用选项<br>

### **查询**

使用 `tile:show` 与 StreamID 加载 tile document 的当前状态：

```Plain
glaze tile:show kjzl6cwe1jw147ww5d8pswh1hjh686mut8v1br10dar8l9a3n1wf8z38l0bg8qa
```

你应该使用你自己的 StreamID，而不是这里包含的 StreamID。\
使用 `stream:state` 与 StreamID 加载 stream 的整个状态：

```Plain
glaze stream:state kjzl6cwe1jw147ww5d8pswh1hjh686mut8v1br10dar8l9a3n1wf8z38l0bg8qa
```

你应该使用你自己的 StreamID，而不是这里包含的 StreamID。<br>

### **更新**

使用 `tile:update` 更新 tile document。注意，你的 DID 必须被指定为流的控制器（作者），才有权限更新它。

```Plain
glaze tile:update kjzl6cwe1jw147ww5d8pswh1hjh686mut8v1br10dar8l9a3n1wf8z38l0bg8qa --key ab...f0 --content '{"Foo":"Baz"}'
```

你应该使用你自己的 StreamID，而不是这里包含的 StreamID。更多选项 您可以使用CLI更改内容和元数据。运行 `glaze tile:update -h` 获取更多信息。<br>

## 数据模型（Schemas）

### **创建数据模型**

Tile documents 可以强制其内容符合数据模型。这些数据模型本身实际上也存储在 tile documents 中，其中的内容是 json-schema。让我们创建一个需要标题和消息的数据模型：

```Plain
glaze tile:create --key ab...f0 --content '{
   "$schema": "http://json-schema.org/draft-07/schema#",
   "title": "Reward",
   "type": "object",
   "properties": {
     "title": {"type": "string"},
     "message": {"type": "string"}
   },
   "required": [
     "message",
     "title"
   ]
 }'
```

<br>

### **选择版本**

首先，使用 `stream:commits` 命令列出 schema stream 中包含的 commits。找到你想使用的特定 commit（版本）。

```Plain
glaze stream:commits kjzl6cwe1jw1472as4pj3b3ahqmkokbmwc7jchqcob6pcixcoo4kxq6ls8uuxgb
```

你应该使用你想强制执行的 json-schema 的 stream 的 StreamID，而不是这里包含的 StreamID。如果一个流包含多个 commits，你不确定你想要哪一个，使用 `tile:show` 命令显示给定 commit 时流的内容。<br>

### **使用数据模型**

当创建一个使用此数据模型的 tile document 时，我们需要使用 commitID 而不是 StreamID，以强制我们使用数据模型的特定版本，因为数据模型的Stream是可变的，可以被更新。要创建符合你的数据模型的Stream，请使用 `tile:create` 命令，并传递 `--metadata` 选项以及你的 commitID：

```Plain
glaze tile:create --key ab...f0 --content '{
    "title": "My first document with schema",
    "message": "Hello World"
  }' --metadata '{"schema":"k3y52l7qbv1frxu8co1hjrivem5cj2oiqtytlku3e4vjo92l67fkkvu6ywuzfxvy8"}'
```

你应该使用你自己的 commitID，而不是这里包含的 commitID。<br>

### **确认**

让我们使用上面的 `stream:state` 命令查看我们刚刚创建的 tile document。我们会看到在 metadata 中正确设置了模式。

```Plain
glaze stream:state kjzl6cwe1jw14b5sr79heovz7fziz4d

xcn8upx3bcesriloqcui137k6rq6g2mn
```

你应该使用你自己的 StreamID，而不是这里包含的 StreamID。


---

# 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://ceramic-zhong-wen-wen-dang.gitbook.io/ceramic-zhong-wen-wen-dang/ceramic-ji-ben-jie-shao/kuai-su-kai-shi.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.
