Convert Figma logo to code with AI

paritytech logosubstrate

Substrate: The platform for blockchain innovators

8,384
2,648
8,384
632

Top Related Projects

1,065

Promise and RxJS APIs around Polkadot and Substrate based chains via RPC calls. It is dynamically generated based on what the Substrate runtime provides in terms of metadata.

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

15,696

Hyperledger Fabric is an enterprise-grade permissioned distributed ledger framework for developing solutions and applications. Its modular and versatile design satisfies a broad range of industry use cases. It offers a unique approach to consensus that enables performance at scale while preserving privacy.

Go implementation of the Ethereum protocol

⟁ Tendermint Core (BFT Consensus) in Go

Reference client for NEAR Protocol

Quick Overview

Substrate is an open-source blockchain development framework created by Parity Technologies. It allows developers to build custom, specialized blockchains for a variety of use cases, providing a flexible and modular architecture that can be easily customized and extended.

Pros

  • Highly modular and flexible, allowing for easy customization of blockchain functionality
  • Supports both proof-of-work and proof-of-stake consensus mechanisms
  • Includes built-in support for upgradeable runtimes, enabling seamless blockchain updates
  • Provides a rich set of pre-built modules (pallets) for common blockchain features

Cons

  • Steep learning curve, especially for developers new to blockchain technology
  • Limited documentation and learning resources compared to more established blockchain platforms
  • Requires knowledge of Rust programming language, which may be unfamiliar to many developers
  • Relatively young ecosystem, with fewer third-party tools and integrations compared to more mature platforms

Code Examples

  1. Defining a custom pallet:
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config: frame_system::Config {
    type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
}

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
    SomethingStored(u32, T::AccountId),
}
  1. Implementing a custom extrinsic (transaction):
#[pallet::call]
impl<T: Config> Pallet<T> {
    #[pallet::weight(10_000)]
    pub fn do_something(origin: OriginFor<T>, something: u32) -> DispatchResult {
        let who = ensure_signed(origin)?;
        <Something<T>>::put(something);
        Self::deposit_event(Event::SomethingStored(something, who));
        Ok(())
    }
}
  1. Querying storage:
#[pallet::storage]
#[pallet::getter(fn something)]
pub type Something<T> = StorageValue<_, u32>;

impl<T: Config> Pallet<T> {
    pub fn get_something() -> u32 {
        Self::something().unwrap_or_default()
    }
}

Getting Started

To start building with Substrate:

  1. Install Rust and required dependencies:

    curl https://sh.rustup.rs -sSf | sh
    rustup default stable
    rustup update nightly
    rustup target add wasm32-unknown-unknown --toolchain nightly
    
  2. Install Substrate and create a new project:

    cargo install substrate-cli
    substrate-node-new my_substrate_project
    cd my_substrate_project
    
  3. Build and run your node:

    cargo build --release
    ./target/release/my-substrate-node --dev
    

Competitor Comparisons

1,065

Promise and RxJS APIs around Polkadot and Substrate based chains via RPC calls. It is dynamically generated based on what the Substrate runtime provides in terms of metadata.

Pros of api

  • Lightweight and focused on JavaScript/TypeScript integration
  • Easier to use for front-end developers and dApp creation
  • More frequent updates and active community support

Cons of api

  • Limited to interacting with existing networks, cannot create new chains
  • Less flexibility for custom runtime logic implementation
  • Dependent on Substrate for core functionality and updates

Code Comparison

Substrate (Rust):

#[pallet::call]
impl<T: Config> Pallet<T> {
    #[pallet::weight(10_000)]
    pub fn do_something(origin: OriginFor<T>, something: u32) -> DispatchResult {
        let who = ensure_signed(origin)?;
        // Function logic here
        Ok(())
    }
}

api (JavaScript):

const api = await ApiPromise.create({ provider: wsProvider });
const txHash = await api.tx.balances
  .transfer(recipient, amount)
  .signAndSend(account);
console.log('Transaction sent with hash', txHash.toHex());

Summary

Substrate is a comprehensive framework for building entire blockchain networks, while api focuses on providing JavaScript/TypeScript interfaces for interacting with existing Substrate-based chains. Substrate offers more flexibility and control over the blockchain's core functionality, whereas api simplifies dApp development and integration with Polkadot ecosystem projects.

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

Pros of Cosmos SDK

  • More modular architecture, allowing for easier customization and extension of blockchain functionality
  • Stronger focus on interoperability between different blockchains through the Inter-Blockchain Communication (IBC) protocol
  • Larger ecosystem of interconnected chains (Cosmos Hub, Osmosis, etc.) built using the SDK

Cons of Cosmos SDK

  • Less flexible in terms of consensus mechanisms, primarily focused on Tendermint
  • Steeper learning curve for developers new to blockchain development
  • Smaller developer community compared to Substrate

Code Comparison

Cosmos SDK (Go):

func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
    var genesisState GenesisState
    if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
        panic(err)
    }
    return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
}

Substrate (Rust):

impl<T: Config> Pallet<T> {
    pub fn do_something(origin: OriginFor<T>, something: u32) -> DispatchResult {
        let who = ensure_signed(origin)?;
        <Something<T>>::put(something);
        Self::deposit_event(Event::SomethingStored(something, who));
        Ok(())
    }
}

Both frameworks offer powerful tools for building custom blockchains, with Cosmos SDK focusing on interoperability and Substrate providing more flexibility in consensus mechanisms and runtime environments.

15,696

Hyperledger Fabric is an enterprise-grade permissioned distributed ledger framework for developing solutions and applications. Its modular and versatile design satisfies a broad range of industry use cases. It offers a unique approach to consensus that enables performance at scale while preserving privacy.

Pros of Fabric

  • Enterprise-focused with permissioned network support
  • Modular architecture allowing for plug-and-play components
  • Strong support for privacy and confidentiality in transactions

Cons of Fabric

  • Steeper learning curve due to complex architecture
  • Less flexibility for public blockchain use cases
  • Slower transaction finality compared to some alternatives

Code Comparison

Fabric (Chaincode in Go):

func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface, id string, value int) error {
    asset := Asset{ID: id, Value: value}
    assetJSON, err := json.Marshal(asset)
    if err != nil {
        return err
    }
    return ctx.GetStub().PutState(id, assetJSON)
}

Substrate (Pallet in Rust):

#[pallet::weight(10_000)]
pub fn create_asset(origin: OriginFor<T>, id: T::AssetId, value: u32) -> DispatchResult {
    let who = ensure_signed(origin)?;
    let asset = Asset { id, value };
    Assets::<T>::insert(&who, asset);
    Ok(())
}

Both repositories offer robust blockchain development frameworks, but cater to different use cases. Fabric excels in enterprise environments with its focus on permissioned networks and privacy, while Substrate provides more flexibility for building custom blockchains, especially for public networks. The code examples demonstrate the different approaches to smart contract development in each framework.

Go implementation of the Ethereum protocol

Pros of go-ethereum

  • Mature and battle-tested implementation of the Ethereum protocol
  • Extensive documentation and large community support
  • Optimized for performance and efficiency in Ethereum mainnet operations

Cons of go-ethereum

  • Less flexible for building custom blockchains or parachains
  • Limited support for alternative consensus mechanisms
  • Slower development cycle for implementing new features

Code Comparison

go-ethereum (Geth):

func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, error) {
    n, err := bc.engine.InsertChain(bc, chain)
    if err != nil {
        return n, err
    }
    return n, nil
}

Substrate:

fn import_block(
    &mut self,
    block: Block<Block::Header, Block::Extrinsic>,
    new_cache: HashMap<CacheKeyId, Vec<u8>>,
) -> sp_blockchain::Result<ImportResult> {
    self.backend.import(BlockImportOperation {
        origin: BlockOrigin::Own,
        header: block.header,
        justification: None,
        post_digests: Vec::new(),
        body: Some(block.extrinsics),
        storage_changes: Default::default(),
        aux_ops: Vec::new(),
    })
}

The code snippets show differences in block import mechanisms, with Substrate offering more flexibility and customization options for blockchain development.

⟁ Tendermint Core (BFT Consensus) in Go

Pros of Tendermint

  • Simpler architecture, easier to understand and implement
  • Better performance for high-throughput applications
  • More mature and battle-tested in production environments

Cons of Tendermint

  • Less flexible and customizable than Substrate
  • Limited support for upgradeability and governance features
  • Smaller ecosystem and fewer tools compared to Substrate

Code Comparison

Tendermint (Go):

func (app *KVStoreApplication) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {
    key, value := req.Tx[:32], req.Tx[32:]
    app.state.Set(key, value)
    return abci.ResponseDeliverTx{Code: 0}
}

Substrate (Rust):

fn execute_block(
    block: Block<Self::Block>,
) -> Result<(Weight, ExtrinsicResults), DispatchError> {
    Executive::execute_block(block)
}

Tendermint uses a simpler key-value store approach, while Substrate offers more complex block execution with weight calculation and error handling. Tendermint's code is more straightforward, reflecting its simpler architecture, while Substrate's code demonstrates its flexibility and advanced features.

Both projects have their strengths, with Tendermint excelling in simplicity and performance, and Substrate offering more customization and features for complex blockchain applications.

Reference client for NEAR Protocol

Pros of NEAR Core

  • Simpler architecture and easier learning curve for developers
  • Faster transaction finality and higher throughput
  • More developer-friendly with support for multiple programming languages

Cons of NEAR Core

  • Less flexible and customizable compared to Substrate's modular design
  • Smaller ecosystem and community support
  • Limited cross-chain interoperability features

Code Comparison

NEAR Core (Rust):

#[near_bindgen]
impl Contract {
    pub fn new() -> Self {
        Self { records: UnorderedMap::new(b"r") }
    }
}

Substrate (Rust):

#[pallet::config]
pub trait Config: frame_system::Config {
    type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
}

Both projects use Rust, but NEAR Core's smart contract syntax is more straightforward, while Substrate's design is more modular and flexible. NEAR Core focuses on simplicity and ease of use, whereas Substrate provides a more customizable framework for building blockchains. Substrate's approach allows for greater flexibility in creating specialized chains, while NEAR Core offers a more streamlined development experience for dApps and smart contracts.

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

Dear contributors and users,

We would like to inform you that we have recently made significant changes to our repository structure. In order to streamline our development process and foster better contributions, we have merged three separate repositories Cumulus, Substrate and Polkadot into a single new repository: the Polkadot SDK. Go ahead and make sure to support us by giving a star ⭐️ to the new repo.

By consolidating our codebase, we aim to enhance collaboration and provide a more efficient platform for future development.

If you currently have an open pull request in any of the merged repositories, we kindly request that you resubmit your PR in the new repository. This will ensure that your contributions are considered within the updated context and enable us to review and merge them more effectively.

We appreciate your understanding and ongoing support throughout this transition. Should you have any questions or require further assistance, please don't hesitate to reach out to us.

Best Regards,

Parity Technologies