# 运行本地网络

您可以运行本地测试网来对 Aptos 区块链进行测试和开发。该网络独立于 Aptos 生态系统运行，仅用于测试和开发。

> 您的本地测试网将不会连接 Aptos 开发网（devnet）

### 开始[​](https://aptos.dev/tutorials/run-a-local-testnet#getting-started) <a href="#getting-started" id="getting-started"></a>

您可以通过两种方式运行本地测试网：使用 Aptos-core 源码或 Docker。

* Aptos-core 源码：在对 Aptos-core 代码库或 Aptos 框架的修改测试时使用。
* Docker：在 Aptos 区块链之上构建服务或在 Aptos 框架上构建应用程序时使用。因为没有构建开销，并且默认情况下，账本状态在网络重新启动时保持不变。

#### 使用 Aptos-core 源码[​](https://aptos.dev/tutorials/run-a-local-testnet#using-aptos-core-source-code) <a href="#using-aptos-core-source-code" id="using-aptos-core-source-code"></a>

1. 从 GitHub 下载并克隆 Aptos-core 项目，并通过运行以下命令准备您的开发环境：

   ```
   git clone https://github.com/aptos-labs/aptos-core.git
   cd aptos
   ./scripts/dev_setup.sh
   source ~/.cargo/env
   ```
2. 运行进程： `cargo run -p aptos-node -- --test`. 启动后，该进程会打印他的配置路径（例如, `/private/var/folders/36/w0v54r116ls44q29wh8db0mh0000gn/T/f62a72f87940e3892a860c21b55b529b/0/node.yaml`）和其他元数据。

注意： 该命令仅从创世账本状态运行 `aptos-node`。如果你想重用之前运行 `aptos-node` 产生的账本，使用 `cargo run -p aptos-node -- --test --config <config-path>`.

#### 使用 Docker[​](https://aptos.dev/tutorials/run-a-local-testnet#using-docker) <a href="#using-docker" id="using-docker"></a>

1. 安装 Docker 和 Docker-Compose。
2. 为你个本地测试验证者网络创建一个目录。
3. 下载 [validator testnet docker compose](https://github.com/aptos-labs/aptos-core/blob/main/docker/compose/validator-testnet/docker-compose.yaml) 和 [validator configuration](https://github.com/aptos-labs/aptos-core/blob/main/docker/compose/validator-testnet/validator_node_template.yaml).
4. 在同一目录下创建配置文件，以便将数据导出到 docker 容器中：

   ```
   # Linux / Mac
   touch genesis.blob aptos_root_key waypoint.txt

   # Windows
   fsutil file createnew genesis.blob 0
   fsutil file createnew aptos_root_key 0
   fsutil file createnew waypoint.txt 0
   Run docker-compose: docker-compose up
   ```

### 和本地测试验证者网络交互[​](https://aptos.dev/tutorials/run-a-local-testnet#interacting-with-the-local-test-validator-network) <a href="#interacting-with-the-local-test-validator-network" id="interacting-with-the-local-test-validator-network"></a>

启动本地测试验证者网络后，您应该会看到以下内容：

```
validator_1  | Entering test mode, this should never be used in production!
validator_1  | Completed generating configuration:
validator_1  |  Log file: "/opt/aptos/var/validator.log"
validator_1  |  Config path: "/opt/aptos/var/0/node.yaml"
validator_1  |  Aptos root key path: "/opt/aptos/var/mint.key"
validator_1  |  Waypoint: 0:7ff525d33f685a5cf26a71b393fa5159874c8f0c2861c382905f49dcb6991cb6
validator_1  |  REST endpoint: 0.0.0.0:8080
validator_1  |  FullNode network: /ip4/0.0.0.0/tcp/7180
validator_1  |  ChainId: TESTING
```

此输出包含启动 Aptos CLI（命令行）工具所需的信息：

* Aptos root key path - 根（也称为铸币 `mint` 或水龙头 `faucet`）密钥控制可以铸币的帐户。 在  docker compose 文件夹中的 `aptos_root_key` 下。
* Waypoint - 区块链中可验证的检查点（在 docker compose 文件夹中的 waypoint.txt 下）
* REST endpoint - `http://127.0.0.1:8080`.
* ChainId - 链 ID，将这条链与其他链区分开。

### 接下来的步骤[​](https://aptos.dev/tutorials/run-a-local-testnet#next-steps) <a href="#next-steps" id="next-steps"></a>

此时，您将在 `0x1` 拥有一个可以执行铸币操作的特殊 root 帐户。

* 如何提交交易：[您的第一笔交易](https://wiki.aptos.movemove.org/jiao-cheng/nin-de-di-yi-bi-jiao-yi)
* 如何创建 Move 模块：[您的第一个 Move 模块](https://wiki.aptos.movemove.org/jiao-cheng/nin-de-di-yi-ge-move-mo-kuai)
* 铸币：[Interacting with the Aptos Blockchain](https://aptos.dev/transactions/interacting-with-the-aptos-blockchain)

需要注意的是，这些方案不包括水龙头。 这留给读者作为练习。
