在 Cosmos 上构建非常简单:你可以通过一条命令启动一条链。本快速开始将在几分钟内带你从零开始,完成链的启动、交易提交以及结果查询。 exampled 是一条简单的 Cosmos SDK 链,用来展示一个可运行应用链的核心组成部分。它包含账户、银行、质押、分配、惩罚、治理等基础构建模块,以及一个自定义的 x/counter 模块。在接下来的教程中,你将先亲手构建该模块的简化版本,然后再逐步了解完整实现。
继续之前,请确保你已完成前置条件中的步骤,以便完成环境配置。

安装二进制文件

运行以下命令以编译 exampled 二进制文件,并将其放到你的 $PATH 中。
make install
运行以下命令验证是否安装成功:
exampled version
你也可以运行以下命令查看所有可用的节点 CLI 命令:
exampled

启动链

运行以下命令启动一条单节点本地链。该命令会自动完成所有设置:初始化链数据、创建测试账户并启动节点。请让它在这个终端中持续运行。
make start

查询计数器

打开第二个终端并查询当前计数:
exampled query counter count
你应该会看到如下输出,这表示计数器的初始值为 0:
{}
你也可以查询该模块的参数:
exampled query counter params
这表明用于递增计数器的费用被存储为模块参数。exampled 链的基础代币面额是 stake。
params:
  add_cost:
    - amount: "100"
      denom: stake
  max_add_value: "100"

提交一笔 Add 交易

发送一笔 Add 交易来递增计数器。该操作会从你用来发送交易、已预先注资的 alice 账户中扣除手续费:
exampled tx counter add 5 --from alice --chain-id demo --yes

再次查询计数器

提交交易后,再次查询计数器以查看更新后的模块状态:
exampled query counter count
你应该会看到如下结果:
count: "5"
恭喜!你刚刚完成了区块链运行、交易提交以及模块状态查询。

下一步

在接下来的教程中,你将:
  1. 从零开始构建该模块的最小版本,以理解核心模式
  2. 逐步了解完整的 x/counter 模块示例,看看它额外加入了什么
  3. 了解模块如何接入链中,以及如何运行完整测试套件
下一步:从零开始构建模块 →
Building on Cosmos is simple: you can start a chain with a single command. This quickstart gets you from zero to a running chain, a submitted transaction, and a queried result in minutes. exampled is a simple Cosmos SDK chain that shows the core pieces of a working app chain. It includes the basic building-block modules for accounts, bank, staking, distribution, slashing, governance, and more, plus a custom x/counter module. In the next tutorials, you’ll build a simple version of that module yourself and then walk through the full implementation.
Before continuing, make sure you have completed the Prerequisites to get your environment set up.

Install the binary

Run the following to compile the exampled binary and place it on your $PATH.
make install
Verify the install by running:
exampled version
You can also run the following to see all available node CLI commands:
exampled

Start the chain

Run the following to start a single-node local chain. It handles all setup automatically: initializes the chain data, creates test accounts, and starts the node. Leave it running in this terminal.
make start

Query the counter

Open a second terminal and query the current count:
exampled query counter count
You should see the following output, which means the counter is starting at 0:
{}
You can also query the module parameters:
exampled query counter params
This shows that the fee to increment the counter is stored as a module parameter. The base coin denomination for the exampled chain is stake.
params:
  add_cost:
    - amount: "100"
      denom: stake
  max_add_value: "100"

Submit an add transaction

Send an Add transaction to increment the counter. This charges a fee from the funded alice account you are sending the transaction from:
exampled tx counter add 5 --from alice --chain-id demo --yes

Query the counter again

After submitting the transaction, query the counter again to see the updated module state:
exampled query counter count
You should see the following:
count: "5"
Congratulations! You just ran a blockchain, submitted a transaction, and queried module state.

Next steps

In the following tutorials, you will:
  1. Build a minimal version of this module from scratch to understand the core pattern
  2. Walk through the full x/counter module example to see what it adds
  3. See how modules are wired into a chain and how to run the full test suite
Next: Build a Module from Scratch →