cosmos-sdk
:chains: A Framework for Building High Value Public Blockchains :sparkles:
Top Related Projects
⟁ Tendermint Core (BFT Consensus) in Go
Go implementation of the Ethereum protocol
Reference client for NEAR Protocol
Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.
Quick Overview
The Cosmos SDK is a framework for building blockchain applications in the Cosmos ecosystem. It provides a modular and extensible architecture, allowing developers to create custom blockchain solutions tailored to their specific needs. The Cosmos SDK is built on top of the Tendermint consensus engine, which ensures the security and reliability of the blockchain network.
Pros
- Modular Design: The Cosmos SDK follows a modular approach, allowing developers to easily add or remove functionality as needed, making it highly customizable.
- Scalability: The Cosmos SDK is designed to be scalable, with the ability to handle a large number of transactions and support multiple blockchain networks.
- Interoperability: The Cosmos SDK is part of the Cosmos ecosystem, which aims to enable interoperability between different blockchain networks.
- Community and Documentation: The Cosmos SDK has a large and active community, with extensive documentation and resources available for developers.
Cons
- Complexity: The Cosmos SDK can be complex to set up and configure, especially for developers new to blockchain technology.
- Performance: While the Cosmos SDK is designed to be scalable, the performance of the blockchain network can still be a concern, depending on the specific use case and the number of transactions.
- Adoption: The Cosmos ecosystem, while growing, is still relatively new compared to other blockchain platforms, which may make it less attractive for some developers.
- Governance: The Cosmos SDK's governance model, while decentralized, can be complex and may not align with the needs of all projects.
Code Examples
Here are a few code examples demonstrating the usage of the Cosmos SDK:
- Creating a New Module:
package mymodule
import (
"github.com/cosmos/cosmos-sdk/types"
)
type MsgSendToAddress struct {
FromAddress types.AccAddress
ToAddress types.AccAddress
Amount types.Coins
}
func (msg MsgSendToAddress) Route() string { return "mymodule" }
func (msg MsgSendToAddress) Type() string { return "send_to_address" }
func (msg MsgSendToAddress) ValidateBasic() error {
// Validate the message fields
return nil
}
- Handling a Transaction:
func handleMsgSendToAddress(ctx sdk.Context, msg MsgSendToAddress) (*sdk.Result, error) {
// Implement the logic to handle the message
err := sendCoinsToAddress(ctx, msg.FromAddress, msg.ToAddress, msg.Amount)
if err != nil {
return nil, err
}
return &sdk.Result{}, nil
}
- Querying the State:
func queryBalance(ctx sdk.Context, req abci.RequestQuery) ([]byte, error) {
var params QueryBalanceParams
err := ctx.Codec.UnmarshalJSON(req.Data, ¶ms)
if err != nil {
return nil, err
}
balance := getBalance(ctx, params.Address)
bz, err := ctx.Codec.MarshalJSON(balance)
if err != nil {
return nil, err
}
return bz, nil
}
Getting Started
To get started with the Cosmos SDK, follow these steps:
-
Install the necessary dependencies:
- Go (version 1.16 or higher)
- Git
-
Clone the Cosmos SDK repository:
git clone https://github.com/cosmos/cosmos-sdk.git -
Navigate to the project directory:
cd cosmos-sdk -
Build the Cosmos SDK:
make install -
Initialize a new Cosmos SDK application:
cosmos-sdk init my-app -
Start the application:
cosmos-sdk start -
Interact with the application using the provided CLI commands:
cosmos-sdk tx send <from_address> <to_address> <amount> cosmos-sdk query balance <address>
For more detailed instructions and documentation, please refer to the [
Competitor Comparisons
⟁ Tendermint Core (BFT Consensus) in Go
Pros of Tendermint
- Focused on consensus and networking, providing a more specialized and optimized solution
- Easier to integrate into existing blockchain projects due to its modular design
- More lightweight and potentially faster for specific use cases
Cons of Tendermint
- Less comprehensive than Cosmos SDK, requiring additional components for full blockchain functionality
- May require more custom development for application-specific features
- Smaller ecosystem and fewer built-in modules compared to Cosmos SDK
Code Comparison
Tendermint (Go):
func (app *Application) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {
// Application-specific transaction processing
return abci.ResponseDeliverTx{Code: 0}
}
Cosmos SDK (Go):
func (app *MyApp) DeliverTx(txBytes []byte) abci.ResponseDeliverTx {
tx, err := app.txDecoder(txBytes)
if err != nil {
return sdkerrors.ResponseDeliverTx(err)
}
result, err := app.runTx(runTxModeDeliver, tx)
return sdkerrors.ResponseDeliverTx(err, result.Data, result.Log, result.GasUsed, result.Events)
}
The code comparison shows that Tendermint focuses on core consensus functionality, while Cosmos SDK provides a more comprehensive framework for building blockchain applications, including transaction processing and state management.
Go implementation of the Ethereum protocol
Pros of go-ethereum
- More established and widely adopted blockchain platform
- Larger developer community and ecosystem
- Robust smart contract functionality with Solidity
Cons of go-ethereum
- Higher transaction fees and slower processing times
- Less flexibility for customization compared to Cosmos SDK
- More complex architecture for developers to work with
Code Comparison
go-ethereum (Ethereum):
func (s *Ethereum) Start() error {
if err := s.engine.Start(); err != nil {
return err
}
return nil
}
cosmos-sdk (Cosmos):
func (app *BaseApp) Start() error {
if err := app.LoadLatestVersion(); err != nil {
return err
}
return nil
}
The code snippets show simplified start functions for both projects. go-ethereum focuses on starting the consensus engine, while cosmos-sdk loads the latest version of the application state.
Both repositories are open-source blockchain platforms, but they serve different purposes. go-ethereum is the official Go implementation of the Ethereum protocol, while cosmos-sdk is a framework for building custom blockchain applications. Cosmos SDK offers more flexibility and interoperability between different blockchains, while Ethereum has a larger ecosystem and more established smart contract capabilities.
Reference client for NEAR Protocol
Pros of nearcore
- Faster transaction finality (1-2 seconds) compared to Cosmos SDK's longer block times
- More developer-friendly with support for multiple programming languages (Rust, AssemblyScript)
- Sharding implementation for improved scalability
Cons of nearcore
- Less mature ecosystem and fewer production-ready applications
- More centralized validator set compared to Cosmos SDK's wider distribution
- Limited interoperability features compared to Cosmos SDK's Inter-Blockchain Communication (IBC)
Code Comparison
nearcore (Rust):
#[near_bindgen]
impl Contract {
pub fn set_greeting(&mut self, message: String) {
self.message = message;
}
}
Cosmos SDK (Go):
func (k Keeper) SetGreeting(ctx sdk.Context, message string) {
store := ctx.KVStore(k.storeKey)
store.Set([]byte("greeting"), []byte(message))
}
Both examples show a simple function to set a greeting message, demonstrating the different syntax and structure between Rust (nearcore) and Go (Cosmos SDK). nearcore uses a more compact attribute-based approach, while Cosmos SDK follows a more explicit keeper pattern for state management.
Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.
Pros of Solana
- Higher transaction throughput and lower latency
- Single-chain architecture, simplifying development and deployment
- Native support for parallel transaction processing
Cons of Solana
- More centralized validator network
- Less flexibility for customizing blockchain functionality
- Steeper learning curve for developers due to unique architecture
Code Comparison
Solana (Rust):
#[derive(BorshSerialize, BorshDeserialize, Debug)]
pub struct Instruction {
pub program_id: Pubkey,
pub accounts: Vec<AccountMeta>,
pub data: Vec<u8>,
}
Cosmos SDK (Go):
type Msg interface {
proto.Message
ValidateBasic() error
GetSigners() []sdk.AccAddress
}
Solana uses a single-language approach with Rust, while Cosmos SDK supports multiple languages through its modular design. Solana's code focuses on low-level instructions, whereas Cosmos SDK emphasizes higher-level abstractions for blockchain development.
Both projects are actively maintained and have strong communities. Solana excels in performance and scalability, making it suitable for high-throughput applications. Cosmos SDK offers greater flexibility and interoperability, allowing developers to create custom blockchain solutions tailored to specific use cases.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Cosmos SDK
The Cosmos SDK is a modular, open-source blockchain SDK for building secure, high-performance Layer 1 chains with full customizability used by 200+ chains in production. Developers can use the Cosmos SDK to easily and quickly spin up custom blockchains that can natively interoperate.
The Cosmos SDK is tailored for building secure, sovereign application-specific blockchains. Developers building with the Cosmos SDK can use predefined modules that cover standard blockchain functionality or create custom modules for their specific use case. This composable architecture enables robust customization. The SDK provides abstractions for permissioning, governance, state management, account abstraction, tokenization processes, application logic, and more.
Cosmos SDK blockchains get interoperability out-of-the-box via a native integration with the Inter-Blockchain Communication Protocol (IBC). ibc-go is implemented as a Go module in the Cosmos SDK.
While the Cosmos SDK is plug-and-play with any consensus engine, we recommend using CometBFT for a fast, battle-tested, high-throughput, configurable BFT state machine. CometBFT is developed as part of the Cosmos Stack and its releases are updated alongside the SDK.
WARNING: The Cosmos SDK has mostly stabilized, but we are still making some breaking changes.
Quick Start
To learn how the Cosmos SDK works from a high-level perspective, see the Cosmos SDK High-Level Intro.
If you want to get started quickly and learn how to build on top of Cosmos SDK, visit Cosmos SDK Tutorials. You can also fork the tutorial's repository to get started building your own Cosmos SDK application.
Note: We advise to always use the latest maintained Go version for building Cosmos SDK applications.
Modules
The Cosmos SDK maintains a set of modules that can be included in your blockchain application. For more information on modules, see our introduction doc.
Maintainers
Cosmos Labs maintains the core components of the stack: Cosmos SDK, CometBFT, IBC, Cosmos EVM, and various developer tools and frameworks. The detailed maintenance policy can be found here. In addition to developing and maintaining the Cosmos Stack, Cosmos Labs provides advisory and engineering services for blockchain solutions. Get in touch with Cosmos Labs.
Cosmos Labs is a wholly-owned subsidiary of the Interchain Foundation, the Swiss nonprofit responsible for treasury management, funding public goods, and supporting governance for Cosmos.
The Cosmos Stack is supported by a robust community of open-source contributors.
History
The Cosmos SDK was first released in 2019, and the first blockchain to use the SDK in production was the Cosmos Hub. Today, the Cosmos SDK is a popular, battle-tested, open-source framework used by hundreds of chains.
The Cosmos Hub still receives the most up-to-date Cosmos SDK versions. The Cosmos Hub application, gaia, has its own cosmos/gaia repository.
Developer Community and Support
The issue list of this repo is exclusively for bug reports and feature requests. We have active, helpful communities on Discord, Telegram, and Slack.
| Need Help? | Support & Community: Discord - Telegram - Talk to an Expert - Join the #Cosmos-tech Slack Channel |
Documentation and Resources
View the Cosmos SDK documentation: https://docs.cosmos.network/
Cosmos Stack Libraries
- CometBFT - High-performance, 10k+ TPS configurable BFT consensus engine.
- The Inter-Blockchain Communication Protocol (IBC) - A blockchain interoperability protocol that allows blockchains to transfer any type of data encoded in bytes.
- Cosmos EVM - Native EVM layer for Cosmos SDK chains.
Disambiguation
This Cosmos SDK project is not related to the React-Cosmos project (yet). Many thanks to Evan Coury and Ovidiu (@skidding) for this Github organization name. As per our agreement, this disambiguation notice will stay here.
Top Related Projects
⟁ Tendermint Core (BFT Consensus) in Go
Go implementation of the Ethereum protocol
Reference client for NEAR Protocol
Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot