Skip to main content

What is app.go?

The app.go file is the core of your Cosmos SDK application. It defines your blockchain application by composing together modules, keepers, and handlers that implement your chain’s functionality. This file is where you wire together all the components that make your blockchain work. The SimApp implementation serves as a reference example and testing application for the Cosmos SDK, demonstrating how to properly structure and initialize a blockchain application.

Core Components

SimApp Struct

The SimApp struct is the main application type that extends the ABCI application. It contains all the necessary components:

Key Initialization Steps

The NewSimApp constructor follows a specific initialization order:

1. Codec Setup

Codecs handle serialization and deserialization of messages and state. The interface registry enables protobuf Any type support.

2. BaseApp Creation

BaseApp provides the core ABCI interface implementation and transaction processing pipeline.

3. Store Keys Registration

Each module gets its own isolated key-value store for persisting state.

4. Keeper Initialization

Keepers are initialized in dependency order. For example, the BankKeeper depends on AccountKeeper:

5. Module Manager Setup

The Module Manager orchestrates module lifecycle operations.

Module Account Permissions

Module accounts are special accounts owned by modules rather than users:
Permissions control what operations each module account can perform (minting, burning, staking).

Execution Order

The Module Manager controls the order of operations during blockchain lifecycle events:

Begin Block Order

This order ensures operations happen in the correct sequence (e.g., slashing happens after reward distribution).

End Block Order

Genesis Order

Genesis initialization must happen in dependency order.

ABCI Lifecycle Methods

The application implements key ABCI methods that CometBFT calls:

InitChainer

Called once when the chain starts to initialize state from genesis.

BeginBlocker & EndBlocker

Called at the beginning and end of each block to perform module-specific logic.

Ante and Post Handlers

AnteHandler

The AnteHandler processes transactions before message execution:
AnteHandlers typically:
  • Verify signatures
  • Deduct fees
  • Check sequence numbers
  • Validate transaction format

PostHandler

PostHandlers run after message execution:
PostHandlers can implement features like transaction tips.

API and Service Registration

The application exposes gRPC and REST APIs:
These routes allow clients to query state and submit transactions via HTTP.

Building Your Own Application

When creating your own blockchain application, follow the patterns demonstrated in SimApp:
  1. Set up codecs and registries for serialization and type handling
  2. Initialize BaseApp with your application name and configuration
  3. Register store keys for each module that needs persistent storage
  4. Initialize module keepers in dependency order (e.g., AccountKeeper before BankKeeper)
  5. Configure the Module Manager with your selected modules
  6. Set execution orders for BeginBlock, EndBlock, and Genesis operations
  7. Configure module account permissions based on your requirements
  8. Set up ante/post handlers for transaction processing
  9. Register services and APIs for client interaction
The key is understanding how components interact and ensuring proper initialization order to avoid dependency issues.

Additional Resources

For hands-on tutorials on running a node, see the Cosmos SDK Node Tutorial.

Complete app.go