Polkadart - The Complete Dart/Flutter SDK for Polkadot

website·Indexed 32 days ago

https://polkadart.dev

A type-safe Dart/Flutter SDK for building decentralized applications on Polkadot and Substrate-based chains. The ecosystem includes a SCALE codec implementation, a type generator for network-specific APIs, and tools for decoding chain data, managing runtime metadata, and interacting with Author, Chain, State, and System APIs.

Tokens
62.2K
Snippets
458
Records
512
Agent score
59%

What's inside Polkadart

  1. Overview of SCALE Compact Encoding

    Compact encoding is a variable-length integer encoding scheme used in SCALE to optimize storage by using fewer bytes for smaller numbers. This is particularly useful for blockchain applications where storage is expensive.

    Storage Efficiency:

    • 1 byte: Values 0-63
    • 2 bytes: Values 64-16,383
    • 4 bytes: Values 16,384-1,073,741,823
    • 5+ bytes: Values $\ge$ 1,073,741,824
  2. Overview of Substrate Storage Hashers

    In Substrate, storage keys are generated by hashing the pallet name, storage item name, and (for maps) the key. The substrate_metadata package provides implementations of these hashers to allow developers to generate the correct storage keys for querying chain state. Different algorithms offer different trade-offs between security and performance.
  3. Overview of interacting with ink! smart contracts using Polkadart

    Polkadart allows Dart developers to interact with ink! smart contracts. The typical workflow involves setting up an ink! development environment, creating and building a contract to Wasm, running a Substrate node, generating Dart bindings via the ink_cli package, and using Polkadart libraries to call contract methods.
  4. Overview of the Polkadart SDK

    Polkadart is a type-safe Dart/Flutter SDK designed for building decentralized applications (dApps) on Polkadot, Substrate, and compatible blockchain networks. It provides comprehensive APIs, automatic code generation, and a Flutter-first design to integrate blockchain functionality into Dart applications. The project is licensed under the Apache 2.0 license.
  5. Overview of Metadata Merkleization

    Metadata Merkleization (defined in RFC-78) is a security feature that allows offline wallets and hardware devices to verify they are using the correct metadata when signing transactions. It prevents malicious metadata from tricking a user into signing an unintended transaction by generating a cryptographic hash (merkle root) of the metadata and including it in the transaction for chain validation. This feature requires Metadata V15; it is not compatible with V14.
  6. Overview of Polkadart for Blockchain Development

    Polkadart is a Dart SDK designed for building decentralized applications on Polkadot and other Substrate-based chains. It leverages Dart's modern development experience to provide compile-time safety through generated types from chain metadata, native compilation for performance, and a single codebase that runs across iOS, Android, Web, Desktop, and Server environments (via Flutter).
  7. Overview of Polkadart SDK

    Polkadart is a type-safe, performant, and production-ready SDK for building decentralized applications (dApps) on Polkadot and Substrate-based chains. It allows developers to use a single codebase to target mobile, web, and desktop platforms (iOS, Android, Web, macOS, Windows, and Linux). Key features include:

    • Type Safety: Auto-generated types from chain metadata to ensure compile-time safety.
    • Performance: Native Dart compilation and an optimized SCALE codec.
    • Smart Contract Support: Full support for ink! smart contracts, including type-safe contract calls and event handling.
    • Cross-Platform: 100% Dart native implementation.
  8. Query blockchain system information using SystemApi

    The SystemApi class from the polkadart package allows developers to query system-level information about a blockchain node, such as its name, version, and health status. To use it, instantiate SystemApi with a Provider (e.g., a WebSocket connection).
    void main() async {
      final provider = Provider.fromUri(Uri.parse('wss://rpc.polkadot.io'));
      final systemApi = SystemApi(provider);
      final chain = await systemApi.chain();
    
      print(chain); // Output: Polkadot
    }
  9. Capabilities of the Polkadart library

    Polkadart allows developers to perform the following tasks on Substrate-based blockchains:

    • Connect to any Substrate-based blockchain.
    • Query and decode storage data.
    • Send transactions and token transfers.
    • Subscribe to real-time blockchain events (e.g., listening to blocks or balance changes).
    • Interact with ink! smart contracts.
    • Sign and verify messages.
  10. Pre-allocate buffers using CompactCodec size hints

    When pre-allocating buffers for variable-length encoding, use the sizeHint(value) method on the codec to determine the expected byte size for a specific value.
    final value = 1000000;
    final expectedSize = CompactCodec.codec.sizeHint(value);
    // Pre-allocate buffer of expectedSize
  11. Generate a metadata hash for transactions

    The metadata hash (digest) is a 32-byte Blake3 hash. Use the digest() method on the MetadataMerkleizer instance. The result is cached after the first call for performance.
    // Generate the hash bytes
    final hashBytes = merkleizer.digest();
    
    // Convert to hex for use in transactions
    final metadataHash = hex.encode(hashBytes);
    
    print('Metadata hash: 0x$metadataHash');