Helius Rust SDK

repository·dev·Indexed 41 days ago

https://github.com/helius-labs/helius-rust-sdk

An asynchronous toolkit for building Solana applications with high-performance access to Helius RPC, WebSockets, and Pre-Confirmation transaction streams. Version 3.0.0 includes support for the Digital Asset System (DAS) API, ZK Compression API, Wallet API, and optimized transaction submission via Helius Sender and Smart Transactions.

Tokens
21.6K
Snippets
69
Records
100
Agent score
2%

What's inside Helius

  1. Corrected behavior for `get_stake_accounts` in 3.0

    dev

    In version 3.0, get_stake_accounts was updated to filter by the Authorized::staker (offset 12) instead of the Authorized::withdrawer (offset 44).

    This change ensures the method returns the correct set of accounts controlled by the staker. If you previously implemented client-side workarounds to filter results, those should now be removed.

  2. Access the embedded Solana client

    dev

    The Helius client embeds a standard Solana client.

    • For synchronous operations, access it via helius.connection().request_name() where request_name() is a standard Solana RPC method.
    • For asynchronous operations (requires new_async() or .with_async_solana()), access it via helius.async_connection()?.some_async_method().await?.
  3. Manage multiple clients with HeliusFactory

    dev

    The HeliusFactory allows for centralized configuration and thread-safe creation of multiple Helius clients. This is useful for managing work across multiple clusters simultaneously while ensuring consistent configuration.

    Key methods:

    • new(): Creates a new HeliusFactory.
    • with_client(reqwest::Client): Provides the factory with its own reqwest client.
    • create(...): Creates multiple Helius clients in a thread-safe manner.
  4. Configure Transaction v1 (SIMD-0385)

    dev

    Agave 4.2 introduces Transaction v1, which increases the maximum transaction size to 4,096 bytes.

    To use v1, set version: TransactionVersion::V1 in your CreateSmartTransactionConfig.

    Important Constraints:

    • v1 uses message header config for compute-unit limits and total priority fees instead of ComputeBudget instructions.
    • Address Lookup Tables (ALTs) are not supported in v1; providing them will result in a rejection.
    • Requires Agave 4.2 (solana-* 4.x).
    • Note: As of this release, Transaction v1 is not yet active on any cluster. Attempting to use it may return UnsupportedVersion during simulation.
    use helius::types::{CreateSmartTransactionConfig, TransactionVersion};
    
    let config = CreateSmartTransactionConfig {
        instructions,
        signers,
        version: TransactionVersion::V1,
        ..Default::default()
    };
    let (tx, _last_valid_block_height) = helius.create_smart_transaction(&config).await?;
  5. Understanding confirmation polling and deadlines in 3.0

    dev

    Version 3.0 introduces several changes to how transaction confirmations are handled:

    • Real Deadlines: The timeout parameter in send_and_confirm_transaction and Sender paths is now a strict deadline. Previously, each poll had its own 15-second budget; now, the total time honored is the specified timeout. Ensure your timeout values reflect your actual desired wait time.
    • Error Propagation: If a transaction fails to send, the method now returns the underlying send error instead of a generic confirmation timeout error.
    • Exponential Backoff: Polling now uses an exponential backoff strategy (starting at 400ms, doubling up to a 5s ceiling) instead of spinning, which reduces network overhead.
  6. Choose a Helius client constructor

    dev

    The SDK provides several ways to instantiate a Helius client depending on your requirements:

    ConstructorUse Case
    Helius::new(api_key, cluster)Basic RPC operations with Helius endpoints
    Helius::new_async(api_key, cluster)Full-featured: async Solana client + WebSocket + confirmed commitment
    Helius::new_with_url(url)Custom RPC endpoint (no API key required)
    HeliusBuilder::new()Advanced configuration (custom timeouts, TLS, etc.)
  7. Migrate Smart-transaction configs from 2.x to 3.0

    dev

    In version 3.0, CreateSmartTransactionConfig and CreateSmartTransactionSeedConfig introduced a new field: loaded_accounts_data_size_limit. This field sets the account-data budget for Transaction v1 messages.

    To prevent breaking changes when new fields are added in the future, use the ..Default::default() syntax when constructing these structs instead of enumerating every field manually.

    // After 3.0 upgrade
    let config = CreateSmartTransactionConfig {
        instructions,
        signers,
        version: TransactionVersion::V1,
        ..Default::default()
    };
  8. Handle Sender and tip-floor errors in 3.0

    dev

    In version 3.0, transport failures for the Sender and Jito tip-floor feed are no longer classified as HeliusError::InvalidInput. They are now classified as HeliusError::Network.

    Instead of matching on error message substrings, use the provided error accessors or specific variants to handle network faults, rate limits, and authorization issues.

    // After 3.0 upgrade
    match helius.send_smart_transaction_with_sender(config, options).await {
        Err(e) if e.is_connect() || e.is_timeout() => retry(),
        Err(HeliusError::RateLimitExceeded { path }) => back_off(&path),
        Err(HeliusError::Unauthorized { .. }) => refresh_credentials(),
        ...
    }
  9. Migrate between major versions of the Helius SDK

    dev
    When upgrading your project across major versions (e.g., from 2.x to 3.0, 1.x to 2.0, or 0.x to 1.0), you must review the breaking changes and update your implementation accordingly. Detailed instructions for each version transition are available in the MIGRATION.md file.
  10. Manage Sender tip ceilings in 3.0

    dev

    In version 3.0, the auto-derived tip from determine_tip_lamports is now capped at DEFAULT_MAX_TIP_LAMPORTS (0.01 SOL).

    If your application requires tipping higher than this limit during periods of high congestion, you must explicitly set a ceiling using one of the following methods:

    • SenderSendOptions::with_max_tip_lamports
    • determine_tip_lamports_with_cap

    Note that setting a ceiling below the tier's minimum tip will result in an error rather than silently paying a lower amount.

  11. Migrate from Helius SDK 2.x to 3.0

    dev

    The 3.0 release focuses on correctness and type refinements. Key changes include:

    • RpcResponse<T> changes: Fields result and id are now Option. If you inspect RpcResponse directly, you must handle the Option (e.g., using .ok_or_else(...)). High-level methods like helius.rpc().get_asset(...) are unaffected and still return T directly.
    • SenderSendOptions is #[non_exhaustive]: You can no longer use struct literals. Use SenderSendOptions::new() and builder methods.
    • ProgramName typo fix: ProgramName::Unkown is now ProgramName::Unknown.
    • Numeric type refinements: GetAssetsByOwner.limit is now Option<u32>, while EnhancedTransaction.fee and .slot are now u64.
    • Smart-transaction configs: CreateSmartTransactionConfig and CreateSmartTransactionSeedConfig now require version and priority_fee_lamports_cap. Use ..Default::default() when using struct literals.
    • Solana dependency alignment: The SDK targets Agave 4.2 (solana-* 4.x). Align your own solana-* dependencies to 4.x if you share types like Instruction or Pubkey.
    • Transaction v1 support: TransactionSubscribeOptions and GetTransactionsForAddressOptions now default max_supported_transaction_version to 1. To force v0-only behavior, set it to Some(0).
    // Handling RpcResponse directly in 3.0
    let asset = response.result.ok_or_else(|| /* your error */)?;
    
    // Constructing SenderSendOptions in 3.0
    let opts = SenderSendOptions::new()
        .with_region(r)
        .with_swqos_only(true);
    
    // Updating Smart Transaction Configs in 3.0
    let config = CreateSmartTransactionConfig {
        instructions,
        signers,
        ..Default::default()
    };