Espresso Cash

repository·master·Indexed 43 days ago

https://github.com/brij-digital/espresso-cash-public

A suite of Dart and Flutter packages for building Solana-based mobile applications. It includes a comprehensive Solana Dart library for JSON RPC API and transaction management, as well as specialized plugins for the Solana Mobile Wallet Adapter (MWA) and Seed Vault SDK. The toolkit provides utilities for Borsh serialization via the borsh and borsh_annotation packages, and a jupiter_aggregator for integrating the Jupiter Quote API.

Tokens
7.6K
Snippets
25
Records
39
Agent score
55%

What's inside Espresso Cash

  1. Overview of Espresso Cash packages

    master

    The espresso-cash-public repository is a collection of Dart packages focused on Solana development, including mobile wallet implementations, RPC clients, and serialization tools.

    Key components include:

    • espressocash_app: A full-fledged mobile wallet for iOS and Android built on the solana library.
    • solana: Implements the Solana transaction codec and the JSON RPC API.
    • jsonrpc_client: A utility used to generate RPC API methods from definitions to maintain DRY principles.
    • Borsh Serialization: Provided via borsh (a code generator for serialization/deserialization) and borsh_annotation (annotations for Dart classes).
    • Mobile Wallet Adapter (MWA): Includes solana_mobile_wallet (a reference implementation of the Solana Mobile Wallet Adapter spec) and solana_mobile_client (the client-side implementation).
    • solana_seed_vault: Implements the Solana Seed Vault SDK for Flutter.
  2. Overview of the solana Dart library

    master

    The solana package is a comprehensive Dart library for interacting with the Solana blockchain. It provides a complete implementation of the JSON RPC API and a subscription client.

    Key capabilities include:

    • Program Support: Built-in implementations for System Program, Token Program, Memo Program, Stake Program, and Associated Token Account Program.
    • Key Management: Support for Hierarchical Deterministic (HD) derivation, BIP39 seed phrases, and raw private key bytes.
    • Transaction Management: Encoding, signing, and building transactions (including offline support). It includes convenience methods to sign and send transactions and listen for signature status changes (e.g., waiting for confirmed or finalized states).
    • NFT Support: Decoding Metaplex NFT metadata.
    • Subscriptions: Full support for the JSON RPC subscription variant of the API.
  3. Use Borsh for Dart class serialization

    master

    To implement Borsh serialization and deserialization for Dart classes, use the borsh and borsh_annotation packages.

    • borsh_annotation provides the annotations required to mark classes for serialization.
    • borsh acts as the code generator that processes these annotations to produce the necessary serialization logic.
  4. Implement Solana Mobile Wallet Adapter (MWA)

    master

    For developers building Solana DApps or wallets on mobile, the repository provides two complementary packages:

    • solana_mobile_wallet: Use this if you are implementing a wallet. It serves as a reference implementation of the Solana Mobile Wallet Adapter spec and includes a Fake Wallet example.
    • solana_mobile_client: Use this if you are building a DApp. It is the client-side implementation for interacting with wallets via MWA and includes a Fake DApp example.
  5. How to add new Solana programs

    master

    You can extend the library by adding new programs. The convention is to create a new subdirectory under lib/src/programs/ named ${program_name}_program.

    Each new program should contain at least two files:

    1. ${program_name}_program.dart: Contains factory constructors that build messages with one or more instructions.
    2. ${program_name}_instructions.dart: Contains factory constructors for single instructions.

    Additional files may be added to separate code from definitions if necessary.

  6. How Espresso Cash architecture works

    master

    Espresso Cash uses a BLoC-inspired architecture designed with Functional Programming principles in mind.

    Key architectural characteristics:

    • BLoCs: Act as pure business-logic components.
    • Immutability: All states and events are implemented as immutable freezed classes.
    • Module Hierarchy:
      • core: Contains core feature modules that other modules can depend on.
      • features: Contains feature-specific modules. Features can depend on core, but should avoid depending on other features to maintain decoupling.
      • l10n: Handles localization and internationalization.
      • app: Contains the main app screens and serves as the minimal entrypoint to the various features.
  7. How to update the RPC client

    master

    To add a missing RPC method or update an outdated one, you must modify the abstract class in lib/src/rpc/client.dart.

    Steps for adding a method:

    1. Add the method definition to the abstract class in lib/src/rpc/client.dart using standard Dart syntax.
    2. If the method requires new parameter or response types, define those classes in the lib/src/rpc/dto/ directory.
    3. Rebuild the package; the implementation for the new method will be automatically generated.

    For deletions, simply remove the method from the abstract class.