- 一条可在本机运行的 Cosmos SDK 链
- 一个由你亲手构建并接入链中的自定义模块
- 对模块、keeper、message 和 query 如何协同工作的清晰认知
示例仓库
本系列中的所有教程都基于 cosmos/example。这是一个围绕自定义x/counter 模块构建的 Cosmos SDK 参考链。
该仓库有两个主要分支:
main:包含完整的链,并已接入完整的x/counter模块。该分支用于快速开始指南。tutorial/start:与上述链相同,但不包含 counter 模块。x/counter目录及其在应用中的接线都被移除,因此你可以通过跟随教程从零开始构建该模块。
tutorial/start 开始。如果你想先浏览最终完成的实现,请使用 main。
本系列包含什么
- 前置条件:安装 Go、Make、Docker 和 Git。克隆仓库,并熟悉项目目录结构。
- 快速开始:在几分钟内构建并运行这条链。提交一笔交易,查询结果,并在亲手构建之前先看看 counter 模块的实际运行效果。
- 从零开始构建模块:逐步构建一个最小化的 counter 模块:proto 定义、keeper、message server、query server,以及应用接线。如果你想理解一个模块是如何组装起来的,请从这里开始。
-
完整模块讲解:逐步讲解
main分支上的完整x/counter实现。涵盖在最小模块之上新增的全部内容:params、受治理控制的 authority、校验、费用、sentinel errors、telemetry、AutoCLI、simulation、block hooks,以及完整的单元测试套件。 - 运行与测试:学习完整的开发工作流,包括运行本地区块链、使用 CLI,以及三层测试体系的实践方式:单元测试、端到端测试和 simulation。
The Cosmos SDK is a developer-first framework for building custom blockchains. This tutorial series shows you how to build a module from scratch, wire it into a chain, and run it locally, all in minutes. By the end, you will have:
- A working Cosmos SDK chain running on your machine
- A custom module you built yourself, wired into the chain
- A clear mental model of how modules, keepers, messages, and queries fit together
The example repo
All tutorials in this series are based on cosmos/example, a reference Cosmos SDK chain built around a customx/counter module.
The repo has two main branches:
main: the complete chain with the fullx/countermodule wired in. This is used in the Quickstart guide.tutorial/start: the same chain without the counter module. Thex/counterdirectory and its app wiring are stripped out so you can build the module from scratch by following the tutorial.
tutorial/start. If you want to browse the finished implementation first, use main.
What’s in this series
- Prerequisites: Install Go, Make, Docker, and Git. Clone the repo and get familiar with the layout.
- Quickstart: Build and run the chain in minutes. Submit a transaction, query the result, and see the counter module in action before you build it yourself.
- Build a Module from Scratch: Build a minimal counter module step by step: proto definitions, keeper, message server, query server, and app wiring. Start here if you want to understand how a module comes together.
-
Full Module Walkthrough: Walk through the complete
x/counterimplementation onmain. Covers everything added on top of the minimal module: params, governance-gated authority, validation, fees, sentinel errors, telemetry, AutoCLI, simulation, block hooks, and a full unit test suite. - Run and Test: Learn the full development workflow: running a local chain, using the CLI, and working with the three layers of testing: unit tests, end-to-end tests, and simulation.