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

# 快速开始

> 使用 API key 发送请求，读取工作区中的矿场。

Public API v2 的基础地址为 `https://api.nonce.app/public-api/v2`。本指南使用工作区 API key，先获取可访问的工作区，再查询其中的矿场。

## 准备 API key

在 [Nonce 应用](https://nonce.app) 中选择目标工作区，打开 **Manage → API Keys**。该入口对具有 `workspace.manage` 权限的用户可见。将密钥保存在服务端环境变量 `NONCE_API_KEY` 中；权限和凭据管理详见[认证与访问权限](/zh/api-guide/v2/authentication)。

## 选择工作区

```bash theme={null}
curl --fail-with-body \
  "https://api.nonce.app/public-api/v2/workspaces" \
  -H "Authorization: Bearer ${NONCE_API_KEY}"
```

请求成功时，响应包含 `success: true`，`data` 数组中列出可访问的工作区。选择目标工作区，将其 `id` 赋给变量 `WORKSPACE_ID`。API 使用工作区 ID，不使用应用网址中的 slug。

`ListWorkspaces` 目前为 beta。响应还包含访问关系和有效权限，完整字段见[接口参考](/api-reference/v2/workspaces/list-workspaces)。

## 查询矿场

```bash theme={null}
curl --fail-with-body \
  "https://api.nonce.app/public-api/v2/workspaces/${WORKSPACE_ID}/farms?page=1&page_size=20" \
  -H "Authorization: Bearer ${NONCE_API_KEY}"
```

`data` 包含当前凭据可访问的矿场，空数组也是有效结果。如果当前 `page` 小于 `pagination.total_pages`，将 `page` 加一后继续请求下一页。

后续查询使用矿场的 `id` 作为路径中的 `farm_id`。接下来可以调用 [List Miners](/api-reference/v2/miners/list-miners) 或 [List Agents](/api-reference/v2/agents/list-agents)。响应字段和错误格式见[请求与响应](/zh/api-guide/v2/requests)。
