Convert Figma logo to code with AI

cosmos logocosmos-sdk

:chains: A Framework for Building High Value Public Blockchains :sparkles:

6,171
3,569
6,171
383

Top Related Projects

⟁ Tendermint Core (BFT Consensus) in Go

Go implementation of the Ethereum protocol

Reference client for NEAR Protocol

12,919

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:

  1. 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
}
  1. 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
}
  1. Querying the State:
func queryBalance(ctx sdk.Context, req abci.RequestQuery) ([]byte, error) {
    var params QueryBalanceParams
    err := ctx.Codec.UnmarshalJSON(req.Data, &params)
    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:

  1. Install the necessary dependencies:

    • Go (version 1.16 or higher)
    • Git
  2. Clone the Cosmos SDK repository:

    git clone https://github.com/cosmos/cosmos-sdk.git
    
  3. Navigate to the project directory:

    cd cosmos-sdk
    
  4. Build the Cosmos SDK:

    make install
    
  5. Initialize a new Cosmos SDK application:

    cosmos-sdk init my-app
    
  6. Start the application:

    cosmos-sdk start
    
  7. 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.

12,919

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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Cosmos SDK

banner

The Cosmos SDK is a framework for building blockchain applications. CometBFT (BFT Consensus) and the Cosmos SDK are written in the Go programming language. Cosmos SDK is used to build Gaia, the implementation of the Cosmos Hub.

WARNING: The Cosmos SDK has mostly stabilized, but we are still making some breaking changes.

Note: Always use the latest maintained Go version for building Cosmos SDK applications.

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.

For more information, see the Cosmos SDK Documentation.

Contributing

See CONTRIBUTING.md for details on how to contribute and participate in our dev calls. If you want to follow the updates or learn more about the latest design then join our Discord.

Tools and Frameworks

The Cosmos ecosystem is vast. Awesome Cosmos is a community-curated list of notable frameworks, modules and tools.

Inter-Blockchain Communication (IBC)

The IBC module for the Cosmos SDK has its own cosmos/ibc-go repository. Go there to build and integrate with the IBC module.

Version Matrix

The version matrix below shows which versions of the Cosmos SDK, modules and libraries are compatible with each other.

Core Dependencies

Core dependencies are the core libraries that an application may depend on. Core dependencies not mentioned here as compatible across all maintained SDK versions.

Cosmos SDKcosmossdk.io/corecosmossdk.io/apicosmossdk.io/x/tx
0.52.z1.y.z0.8.z0.14.z
0.50.z0.11.z0.7.z0.13.z
0.47.z0.5.z0.3.zN/A

Module Dependencies

Module Dependencies are the modules that an application may depend on and which version of the Cosmos SDK they are compatible with.

Note: The version table only goes back to 0.50.x, as modules started to become modular with 0.50.z. X signals that the module was not spun out into its own go.mod file. N/A signals that the module was not available in the Cosmos SDK at that time.

Cosmos SDK0.50.z0.52.z
cosmossdk.io/x/accountsN/A0.2.z
cosmossdk.io/x/bankX0.2.z
cosmossdk.io/x/circuit0.1.z0.2.z
cosmossdk.io/x/consensusX0.2.z
cosmossdk.io/x/distributionX0.2.z
cosmossdk.io/x/epochsN/A0.2.z
cosmossdk.io/x/evidence0.1.z0.2.z
cosmossdk.io/x/feegrant0.1.z0.2.z
cosmossdk.io/x/govX0.2.z
cosmossdk.io/x/groupX0.2.z
cosmossdk.io/x/mintX0.2.z
cosmossdk.io/x/nft0.1.z0.2.z
cosmossdk.io/x/protocolpoolN/A0.2.z
cosmossdk.io/x/slashingX0.2.z
cosmossdk.io/x/stakingX0.2.z
cosmossdk.io/x/upgrade0.1.z0.2.z

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.