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

# 加入网络

本指南将引导你完成在本地设置独立网络以及在 Mainnet 或 Testnet 上运行节点的过程。

你还可以在相应的选项卡中找到每个网络的硬件要求。

<Tabs>
  <Tab title="本地网络">
    要轻松设置本地节点，请从 [injective-core](https://github.com/InjectiveFoundation/injective-core) 仓库下载并运行 `setup.sh` 脚本。请使用与已安装的 `injectived` 版本匹配的脚本版本。

    ```bash theme={null}
    # 将版本标签替换为与你的 injectived 二进制文件匹配的版本
    wget https://raw.githubusercontent.com/InjectiveFoundation/injective-core/v1.18.3/setup.sh
    chmod +x ./setup.sh # 使脚本可执行
    ./setup.sh
    ```

    例如，使用 v1.17.2 的脚本：

    ```bash theme={null}
    wget https://raw.githubusercontent.com/InjectiveFoundation/injective-core/v1.17.2/setup.sh
    chmod +x ./setup.sh
    ./setup.sh
    ```

    <Callout icon="warning" color="#FFA500" iconType="regular">
      旧版 [injective-chain-releases](https://github.com/InjectiveLabs/injective-chain-releases) 仓库中的 `setup.sh` 脚本已过时，仅兼容 `injectived` v1.14.1。请始终使用 [InjectiveFoundation/injective-core](https://github.com/InjectiveFoundation/injective-core) 仓库中与你的链版本对应的脚本。
    </Callout>

    通过运行以下命令启动节点：

    ```bash theme={null}
    injectived start # 运行此命令后应该开始产生区块
    ```

    有关脚本执行内容的进一步说明以及对设置过程的更精细控制，请继续阅读下文。

    #### 初始化链

    在运行 Injective 节点之前，我们需要初始化链以及节点的 genesis 文件：

    ```bash theme={null}
    # <moniker> 参数是你节点的自定义用户名。它应该是人类可读的。
    injectived init <moniker> --chain-id=injective-1
    ```

    上述命令创建节点运行所需的所有配置文件以及定义网络初始状态的默认 genesis 文件。所有这些配置文件默认位于 `~/.injectived` 中，但你可以通过传递 `--home` 标志来覆盖此文件夹的位置。请注意，如果你选择使用 `~/.injectived` 以外的目录，则每次运行 `injectived` 命令时都必须使用 `--home` 标志指定位置。如果你已有 genesis 文件，可以使用 `--overwrite` 或 `-o` 标志覆盖它。

    `~/.injectived` 文件夹具有以下结构：

    ```bash theme={null}
    .                                   # ~/.injectived
      |- data                           # 包含节点使用的数据库。
      |- config/
          |- app.toml                   # 应用程序相关配置文件。
          |- config.toml                # Tendermint 相关配置文件。
          |- genesis.json               # genesis 文件。
          |- node_key.json              # 用于 p2p 协议中节点身份验证的私钥。
          |- priv_validator_key.json    # 用于共识协议中作为 validator 的私钥。
    ```

    #### 修改 `genesis.json` 文件

    此时，需要修改 `genesis.json` 文件：

    * 将 staking `bond_denom`、crisis `denom`、gov `denom` 和 mint `denom` 的值更改为 `"inj"`，因为这是 Injective 的原生 token。

    可以通过运行以下命令轻松完成：

    ```bash theme={null}
    cat $HOME/.injectived/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="inj"' > $HOME/.injectived/config/tmp_genesis.json && mv $HOME/.injectived/config/tmp_genesis.json $HOME/.injectived/config/genesis.json
    cat $HOME/.injectived/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="inj"' > $HOME/.injectived/config/tmp_genesis.json && mv $HOME/.injectived/config/tmp_genesis.json $HOME/.injectived/config/genesis.json
    cat $HOME/.injectived/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="inj"' > $HOME/.injectived/config/tmp_genesis.json && mv $HOME/.injectived/config/tmp_genesis.json $HOME/.injectived/config/genesis.json
    cat $HOME/.injectived/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="inj"' > $HOME/.injectived/config/tmp_genesis.json && mv $HOME/.injectived/config/tmp_genesis.json $HOME/.injectived/config/genesis.json
    ```

    <Callout icon="info" color="#07C1FF" iconType="regular">
      上述命令仅在使用默认 `.injectived` 目录时有效。对于特定目录，请修改上述命令或手动编辑 `genesis.json` 文件以反映更改。
    </Callout>

    #### 为 Validator 账户创建密钥

    在启动链之前，你需要用至少一个账户填充状态。为此，首先在 `test` keyring backend 下创建一个名为 `my_validator` 的新账户（可以选择其他名称和其他 backend）：

    ```bash theme={null}
    injectived keys add my_validator --keyring-backend=test

    # 将生成的地址放入变量中以供后续使用。
    MY_VALIDATOR_ADDRESS=$(injectived keys show my_validator -a --keyring-backend=test)
    ```

    现在你已创建本地账户，继续在链的 genesis 文件中授予它一些 `inj` token。这样做还将确保你的链从创世开始就知道此账户的存在：

    ```bash theme={null}
    injectived add-genesis-account $MY_VALIDATOR_ADDRESS 100000000000000000000000000inj --chain-id=injective-1
    ```

    `$MY_VALIDATOR_ADDRESS` 是保存 keyring 中 `my_validator` 密钥地址的变量。Injective 中的 token 具有 `{amount}{denom}` 格式：`amount` 是 18 位精度的十进制数，`denom` 是带有其面额键的唯一 token 标识符（例如 `inj`）。这里我们授予 `inj` token，因为 `inj` 是 `injectived` 中用于 staking 的 token 标识符。

    #### 将 Validator 添加到链

    现在你的账户有了一些 token，你需要向链添加一个 validator。Validator 是参与共识过程以向链添加新区块的特殊全节点。任何账户都可以声明其成为 validator 运营者的意图，但只有获得足够委托的账户才能进入活跃集。在本指南中，你将把本地节点（通过上面的 `init` 命令创建）添加为链的 validator。可以在链首次启动之前通过包含在 genesis 文件中的特殊交易（称为 `gentx`）声明 validator：

    ```bash theme={null}
    # 创建 gentx。
    injectived genesis gentx my_validator 1000000000000000000000inj --chain-id=injective-1 --keyring-backend=test

    # 将 gentx 添加到 genesis 文件。
    injectived genesis collect-gentxs
    ```

    `gentx` 做三件事：

    1. 将你创建的 `validator` 账户注册为 validator 运营者账户（即控制 validator 的账户）。
    2. 自委托提供的 staking token `amount`。
    3. 将运营者账户与用于签署区块的 Tendermint 节点公钥链接。如果未提供 `--pubkey` 标志，则默认为通过上面的 `injectived init` 命令创建的本地节点公钥。

    有关 `gentx` 的更多信息，请使用以下命令：

    ```bash theme={null}
    injectived genesis gentx --help
    ```

    #### 使用 `app.toml` 和 `config.toml` 配置节点

    两个配置文件会自动生成在 `~/.injectived/config` 中：

    * `config.toml`：用于配置 Tendermint（在 [Tendermint 文档](https://docs.tendermint.com/v0.34/tendermint-core/configuration.html)中了解更多），以及
    * `app.toml`：由 Cosmos SDK（Injective 基于此构建）生成，用于状态修剪策略、遥测、gRPC 和 REST 服务器配置、状态同步等配置。

    两个文件都有详细注释——请直接参考它们来调整你的节点。

    一个需要调整的示例配置是 `app.toml` 中的 `minimum-gas-prices` 字段，它定义了 validator 节点愿意接受的处理交易的最低 gas 价格。如果为空，请确保编辑该字段并设置某个值，例如 `10inj`，否则节点将在启动时停止。在本教程中，让我们将最低 gas 价格设置为 0：

    ```toml theme={null}
     # validator 愿意接受的处理交易的最低 gas 价格。
     # 交易的费用必须满足此配置中指定的任何面额的最低要求
     # （例如 0.25token1;0.0001token2）。
     minimum-gas-prices = "0inj"
    ```

    #### 运行本地网络

    现在一切都已设置好，你终于可以启动节点了：

    ```bash theme={null}
    injectived start # 运行此命令后应该开始产生区块
    ```

    此命令允许你运行单个节点，这足以通过节点与链交互，但你可能希望同时运行多个节点以查看它们之间如何达成共识。
  </Tab>

  <Tab title="Testnet 网络">
    #### 硬件规格

    节点运营者应部署裸机服务器以实现最佳性能。此外，validator 节点必须满足推荐的硬件规格，特别是 CPU 要求，以确保高正常运行时间。

    |      *最低要求*     |      *推荐配置*     |
    | :-------------: | :-------------: |
    |   RAM 内存 128GB  |   RAM 内存 128GB  |
    |     CPU 12 核    |     CPU 16 核    |
    | CPU 基础频率 3.7GHz | CPU 基础频率 4.2GHz |
    |   存储 2TB NVMe   |   存储 2TB NVMe   |
    |    网络 1Gbps+    |    网络 1Gbps+    |

    #### 安装 `injectived` 和 `peggo`

    请参阅 [Injective releases repo](https://github.com/InjectiveLabs/testnet/releases) 获取最新版本。非 validator 节点运营者不需要安装 `peggo`。

    ```bash theme={null}
    wget https://github.com/InjectiveLabs/testnet/releases/latest/download/linux-amd64.zip
    unzip linux-amd64.zip
    sudo mv peggo /usr/bin
    sudo mv injectived /usr/bin
    sudo mv libwasmvm.x86_64.so /usr/lib 
    ```

    #### 初始化新的 Injective 链节点

    在运行 Injective 节点之前，我们需要初始化链以及节点的 genesis 文件：

    ```bash theme={null}
    # <moniker> 参数是你节点的自定义用户名，它应该是人类可读的。
    export MONIKER=<moniker>
    # Injective Testnet 的 chain-id 为 "injective-888"
    injectived init $MONIKER --chain-id injective-888
    ```

    运行 `init` 命令将在 `~/.injectived` 创建 `injectived` 默认配置文件。

    #### 准备配置以加入 Testnet

    你现在应该使用 Testnet 的 genesis 文件和应用程序配置文件更新默认配置，并使用种子节点配置你的持久对等节点。

    ```bash theme={null}
    git clone https://github.com/InjectiveLabs/testnet.git

    # 将 genesis 文件复制到配置目录
    aws s3 cp --no-sign-request s3://injective-snapshots/testnet/genesis.json .
    mv genesis.json ~/.injectived/config/

    # 将配置文件复制到配置目录
    cp testnet/corfu/70001/app.toml  ~/.injectived/config/app.toml
    cp testnet/corfu/70001/config.toml ~/.injectived/config/config.toml
    ```

    你还可以验证 genesis 校验和 - a4abe4e1f5511d4c2f821c1c05ecb44b493eec185c0eec13b1dcd03d36e1a779

    ```bash theme={null}
    sha256sum ~/.injectived/config/genesis.json
    ```

    #### 为 `injectived` 配置 `systemd` 服务

    编辑 `/etc/systemd/system/injectived.service` 的配置：

    ```bash theme={null}
    [Unit]
      Description=injectived

    [Service]
      WorkingDirectory=/usr/bin
      ExecStart=/bin/bash -c '/usr/bin/injectived --log-level=error start'
      Type=simple
      Restart=always
      RestartSec=5
      User=root

    [Install]
      WantedBy=multi-user.target
    ```

    启动和重启 systemd 服务

    ```bash theme={null}
    sudo systemctl daemon-reload
    sudo systemctl restart injectived
    sudo systemctl status injectived

    # 启用系统启动时自动启动
    sudo systemctl enable injectived

    # 查看日志
    journalctl -u injectived -f
    ```

    #### 与网络同步

    请参阅 [Polkachu Injective Testnet Node Snapshot](https://polkachu.com/testnets/injective/snapshots) 下载快照并与网络同步。

    **支持**

    如有任何其他问题，你可以随时通过 [Discord](https://discord.gg/injective)、[Telegram](https://t.me/joininjective) 或[电子邮件](mailto:contact@injectivelabs.org)与 Injective 团队联系。
  </Tab>

  <Tab title="Mainnet 网络">
    #### 硬件规格

    节点运营者应部署裸机服务器以实现最佳性能。此外，validator 节点必须满足推荐的硬件规格，特别是 CPU 要求，以确保高正常运行时间。

    |      *最低要求*     |      *推荐配置*     |
    | :-------------: | :-------------: |
    |   RAM 内存 128GB  |   RAM 内存 128GB  |
    |     CPU 12 核    |     CPU 16 核    |
    | CPU 基础频率 3.7GHz | CPU 基础频率 4.2GHz |
    |   存储 2TB NVMe   |   存储 2TB NVMe   |
    |    网络 1Gbps+    |    网络 1Gbps+    |

    #### 安装 `injectived` 和 `peggo`

    请参阅 [Injective core releases](https://github.com/InjectiveFoundation/injective-core/releases) 获取最新版本。非 validator 节点运营者不需要安装 `peggo`。

    ```bash theme={null}
    # 将 URL 替换为 https://github.com/InjectiveFoundation/injective-core/releases 中的最新版本
    wget https://github.com/InjectiveFoundation/injective-core/releases/latest/download/linux-amd64.zip
    unzip linux-amd64.zip
    sudo mv peggo /usr/bin
    sudo mv injectived /usr/bin
    sudo mv libwasmvm.x86_64.so /usr/lib 
    ```

    #### 初始化新的 Injective 节点

    在运行 Injective 节点之前，我们需要初始化链以及节点的 genesis 文件：

    ```bash theme={null}
    # <moniker> 参数是你节点的自定义用户名。它应该是人类可读的。
    export MONIKER=<moniker>
    # Injective Mainnet 的 chain-id 为 "injective-1"
    injectived init $MONIKER --chain-id injective-1
    ```

    运行 `init` 命令将在 `~/.injectived` 创建 `injectived` 默认配置文件。

    #### 准备配置以加入 Mainnet

    你现在应该使用 Mainnet 的 genesis 文件和应用程序配置文件更新默认配置，并使用种子节点配置你的持久对等节点。

    ```bash theme={null}
    git clone https://github.com/InjectiveLabs/mainnet-config

    # 将 genesis 文件复制到配置目录
    cp mainnet-config/10001/genesis.json ~/.injectived/config/genesis.json

    # 将配置文件复制到配置目录
    cp mainnet-config/10001/app.toml  ~/.injectived/config/app.toml
    ```

    你还可以验证 genesis 校验和 - 573b89727e42b41d43156cd6605c0c8ad4a1ce16d9aad1e1604b02864015d528

    ```bash theme={null}
    sha256sum ~/.injectived/config/genesis.json
    ```

    然后使用 `mainnet-config/10001/seeds.txt` 的内容更新 `~/.injectived/config/config.toml` 中的 `seeds` 字段，并将 `timeout_commit` 更新为 `300ms`。

    ```bash theme={null}
    cat mainnet-config/10001/seeds.txt
    nano ~/.injectived/config/config.toml
    ```

    #### 为 `injectived` 配置 `systemd` 服务

    编辑 `/etc/systemd/system/injectived.service` 的配置：

    ```bash theme={null}
    [Unit]
      Description=injectived

    [Service]
      WorkingDirectory=/usr/bin
      ExecStart=/bin/bash -c '/usr/bin/injectived --log-level=error start'
      Type=simple
      Restart=always
      RestartSec=5
      User=root

    [Install]
      WantedBy=multi-user.target
    ```

    启动和重启 systemd 服务：

    ```bash theme={null}
    sudo systemctl daemon-reload
    sudo systemctl restart injectived
    sudo systemctl status injectived

    # 启用系统启动时自动启动
    sudo systemctl enable injectived

    # 查看日志
    journalctl -u injectived -f
    ```

    在将快照数据加载到正确目录之前应停止服务，之后再启动。

    ```bash theme={null}
    # 停止节点
    sudo systemctl stop injectived

    # 启动节点
    sudo systemctl start injectived
    ```

    #### 与网络同步

    **选项 1. State-Sync**

    *即将添加*

    **选项 2. 快照**

    **已修剪**

    1. [Polkachu](https://polkachu.com/tendermint_snapshots/injective)。
    2. [HighStakes](https://tools.highstakes.ch/files/injective.tar.gz)。
    3. [Imperator](https://www.imperator.co/services/chain-services/mainnets/injective)。
    4. [Bware Labs](https://bwarelabs.com/snapshots)。
    5. [AutoStake](https://autostake.com/networks/injective/#validator)。

    如果 Injective `mainnet-config seeds.txt` 列表不起作用（节点无法同步区块），ChainLayer、Polkachu 和 Autostake 维护对等节点列表（可在 `config.toml` 的 `persistent_peers` 字段中使用）或地址簿（用于更快的对等节点发现）。

    **支持**

    如有任何其他问题，你可以随时通过 [Discord](https://discord.gg/injective)、[Telegram](https://t.me/joininjective) 或[电子邮件](mailto:contact@injectivelabs.org)与 Injective 团队联系。
  </Tab>
</Tabs>
