exampled 是一条简单的 Cosmos SDK 链,用来展示一个可运行应用链的核心组成部分。它包含账户、银行、质押、分配、惩罚、治理等基础构建模块,以及一个自定义的 x/counter 模块。在接下来的教程中,你将先亲手构建该模块的简化版本,然后再逐步了解完整实现。
继续之前,请确保你已完成前置条件中的步骤,以便完成环境配置。
安装二进制文件
运行以下命令以编译exampled 二进制文件,并将其放到你的 $PATH 中。
启动链
运行以下命令启动一条单节点本地链。该命令会自动完成所有设置:初始化链数据、创建测试账户并启动节点。请让它在这个终端中持续运行。查询计数器
打开第二个终端并查询当前计数:0:
exampled 链的基础代币面额是 stake。
提交一笔 Add 交易
发送一笔Add 交易来递增计数器。该操作会从你用来发送交易、已预先注资的 alice 账户中扣除手续费:
再次查询计数器
提交交易后,再次查询计数器以查看更新后的模块状态:下一步
在接下来的教程中,你将:- 从零开始构建该模块的最小版本,以理解核心模式
- 逐步了解完整的
x/counter模块示例,看看它额外加入了什么 - 了解模块如何接入链中,以及如何运行完整测试套件
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 theexampled binary and place it on your $PATH.
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.Query the counter
Open a second terminal and query the current count:0:
exampled chain is stake.
Submit an add transaction
Send anAdd transaction to increment the counter. This charges a fee from the funded alice account you are sending the transaction from:
Query the counter again
After submitting the transaction, query the counter again to see the updated module state:Next steps
In the following tutorials, you will:- Build a minimal version of this module from scratch to understand the core pattern
- Walk through the full
x/countermodule example to see what it adds - See how modules are wired into a chain and how to run the full test suite