Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/tx/signing"
"github.com/cosmos/gogoproto/proto"

// counter tutorial app wiring 1: add counter imports here
counter "github.com/cosmos/example/x/counter"
counterkeeper "github.com/cosmos/example/x/counter/keeper"
countertypes "github.com/cosmos/example/x/counter/types"
Expand Down Expand Up @@ -115,6 +116,7 @@ type ExampleApp struct {
StakingKeeper *stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
// counter tutorial app wiring 2: add the counter keeper field here
CounterKeeper *counterkeeper.Keeper

// the module manager
Expand Down Expand Up @@ -172,6 +174,7 @@ func NewExampleApp(
slashingtypes.StoreKey,
govtypes.StoreKey,
consensusparamtypes.StoreKey,
// counter tutorial app wiring 3: add the counter store key here
countertypes.StoreKey,
)

Expand Down Expand Up @@ -280,6 +283,7 @@ func NewExampleApp(
),
)

// counter tutorial app wiring 4: create the counter keeper here
app.CounterKeeper = counterkeeper.NewKeeper(runtime.NewKVStoreService(keys[countertypes.StoreKey]), appCodec, app.BankKeeper)

app.ModuleManager = module.NewManager(
Expand All @@ -295,6 +299,7 @@ func NewExampleApp(
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, nil),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, nil),
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
// counter tutorial app wiring 5: register the counter module here
counter.NewAppModule(appCodec, app.CounterKeeper),
)

Expand Down Expand Up @@ -329,13 +334,15 @@ func NewExampleApp(
distrtypes.ModuleName,
slashingtypes.ModuleName,
stakingtypes.ModuleName,
// counter tutorial app wiring 6: add the counter module to genesis order here
countertypes.ModuleName,
genutiltypes.ModuleName,
)
app.ModuleManager.SetOrderEndBlockers(
banktypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
// counter tutorial app wiring 7: add the counter module to export order here
countertypes.ModuleName,
genutiltypes.ModuleName,
)
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorial-00-prerequisites.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ example/
└── Makefile # Build, test, and dev commands
```

**Where to make changes:**
The tutorials in this section will walk you through the most common kinds of chain changes and show you where they usually live in the repo:

- Adding or modifying a module `x/<module>/` and `proto/`
- Wiring a module into the chain `app.go`
- Changing the binary or CLI `exampled/`
- Running the chain or tests `Makefile` targets
- Add or modify a module: `x/<module>/` and `proto/`
- Wire a module into the chain: `app.go`
- Change the binary or CLI: `exampled/`
- Run the chain or tests: `Makefile` targets

---

Expand Down
46 changes: 31 additions & 15 deletions docs/tutorial-01-quickstart.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
# Quickstart

This page gets the example chain running in a few minutes so you can see the counter module working before building it yourself.
`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.

This quickstart gets you running `exampled`, submitting a transaction, and querying the result as quickly as possible. It also includes the `x/counter` module, which stores a single counter value, lets you query the current count, and lets you submit `Add` transactions to increment it. In the next tutorials, you'll build a simple version of this module yourself and then walk through the full implementation and its additional features.

## Install the binary

Run the following to compile the `exampled` binary and place it on your `$PATH`.

```bash
make install
```

This compiles the `exampled` binary and places it on your `$PATH`.

Verify:
Verify the install by running:

```bash
exampled version
```

You can also run the following to see all available node CLI commands:

```bash
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.

```bash
make start
```

This starts 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:
Expand All @@ -32,16 +40,21 @@ Open a second terminal and query the current count:
exampled query counter count
```

```
count: "0"
You should see the following output, which means the counter is starting at `0`:


```text
{}
```

Query the module parameters:
You can also query the module parameters:

```bash
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`.

```yaml
params:
add_cost:
Expand All @@ -52,32 +65,35 @@ params:

## Submit an add transaction

The `alice` account is funded at chain start. Send 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:

```bash
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:

```bash
exampled query counter count
```

You should see the following:

```
count: "5"
```

The counter incremented by 5.
Congratulations! You just ran a blockchain, submitted a transaction, and queried module state.

## What you just ran
## Next steps

The chain is running the `x/counter` module — the production counter module in this repository. In the following tutorials you will:
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 production `x/counter` to see what it adds
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 →](./tutorial-02-build-a-module.md)
Loading