百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
H

helius-rust-sdk

> 编程语言
开源

异步 Helius Rust SDK

186 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

异步 Helius Rust SDK

Helius SDK

An asynchronous Helius Rust SDK for building the future of Solana

Documentation

The latest documentation can be found here on docs.rs

Changelog

See CHANGELOG.md for the full release history.

Contributions

Interested in contributing to the Helius Rust SDK? Read the following contributions guide before opening up a pull request!

Installation

To start using the Helius Rust SDK in your project, add it as a dependency via cargo. Open your project's Cargo.toml and add the following line under [dependencies]:

toml
helius = "x.y.z"

where x.y.z is your desired version. Alternatively, use cargo add helius to add the dependency directly via the command line. This will automatically find the latest version compatible with your project and add it to your Cargo.toml.

Remember to run cargo update regularly to fetch the latest version of the SDK.

TLS Options

The Helius Rust SDK uses the native TLS implementation by default via:

toml
[dependencies]
helius = "x.y.z"

However, the SDK also supports rustls. Add the following to your Cargo.toml to use rustls instead of the native TLS implementation:

toml
[dependencies]
helius = { version = "x.y.z", default-features = false, features = ["rustls"] }

Using rustls may be preferred in environments where OpenSSL is not available or when a pure Rust TLS implementation is desired. However, it may not support all the same features as the native TLS implementation

Usage

Quick Start

The SDK provides a Helius instance that can be configured with an API key and a given Solana cluster. Developers can generate a new API key on the Helius Developer Dashboard. This instance acts as the main entry point for interacting with the SDK by providing methods to access different Solana and RPC client functionalities.

There are three simple constructors and a builder for advanced configuration:

Constructor Use 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.)

Helius::new() — Basic Client

The simplest way to get started. Creates a client for standard Helius RPC operations. This constructor is synchronous:

…

Helius::new_async() — Full-Featured Client

The recommended constructor for production applications. Includes async Solana RPC, WebSocket streaming, and confirmed commitment level:

rust
use helius::Helius;
use helius::types::Cluster;

#[tokio::main]
async fn main() {
    let helius = Helius::new_async("YOUR_API_KEY", Cluster::MainnetBeta)
        .await
        .expect("Failed to create client");

    // Async Solana RPC
    let async_client = helius.async_connection().expect("Async client available");

    // Enhanced WebSocket streaming
    let ws = helius.ws().expect("WebSocket available");
}

Helius::new_with_url() — Custom RPC Endpoint

Use your own RPC node, a third-party provider, or localhost for development. No API key required. This constructor is synchronous:

rust
use helius::Helius;

fn main() {
    // Custom RPC provider
    let helius = Helius::new_with_url("https://my-rpc-provider.com/")
        .expect("Failed to create client");

    // Local development
    let local = Helius::new_with_url("http://localhost:8899")
        .expect("Failed to create client");
}

HeliusBuilder — Advanced Configuration

For fine-grained control over the client configuration, use the builder pattern:

…

HeliusFactory

The SDK also comes equipped with HeliusFactory, a factory for creating instances of Helius. This factory allows for a centralized configuration and creation of Helius clients so work can be done across multiple clusters at the same time. Using a factory simplifies client code and enhances maintainability by ensuring that all Helius clients are configured consistently. It has the following functionality:

  • A new method used to create a new HeliusFactory capable of producing Helius clients. Note this method does not create a reqwest client
  • A with_client method used to provide a given HeliusFactory created with the new method its own reqwest client
  • A create method used to create multiple Helius clients in a thread-safe manner

Embedded Solana Client

The Helius client has an embedded Solana client that can be accessed via helius.connection().request_name() where request_name() is a given RPC method. A full list of all Solana RPC HTTP methods can be found here.

For asynchronous operations, use Helius::new_async() or HeliusBuilder with .with_async_solana(). The async client can be accessed via helius.async_connection()?.some_async_method().await? where some_async_method() is a given async RPC method.

Enhanced WebSockets

Use Helius::new_async() or HeliusBuilder with .with_websocket(None, None) to create a client with WebSocket support. This enables our Enhanced WebSocket methods transactionSubscribe and accountSubscribe

Pre Confirmations (preconfSubscribe)

Pre Confirmations are Helius's lowest-latency transaction stream: scheduled transactions are delivered over WebSocket before they are shredded. A pre-confirmation is an early signal, not a guarantee — a streamed transaction may still fail to land. Coverage is not continuous: it scales with the share of stake forwarding scheduled transactions to Helius, so expect gaps. Pricing is credit-based (10 credits per notification message), the same model as other Helius WebSocket subscriptions.

Served from the Gatekeeper endpoint (wss://beta.helius-rpc.com). Despite the beta host name this is not a beta product — it is where Pre Confirmations launch during the Gatekeeper migration.

Use the standalone PreconfClient:

rust
use futures_util::StreamExt;
use helius::preconf::PreconfClient;

let (client, mut stream) = PreconfClient::connect_with_api_key("your_api_key").await?;
while let Some(event) = stream.next().await {
    // event: { version, slot, transaction_index, status, transaction, transaction_bytes }
    println!("v{} slot={} index={} status={:?}", event.version, event.slot, event.transaction_index, event.status);
}
client.shutdown().await?;

preconfSubscribe takes no filter parameters — it streams all scheduled transactions. Notifications are binary frames (the subscribe ack is a JSON text frame); the layout is little-endian version:u8 | slot:u64_le | transaction_index:u64_le | status:u8 | bincode(VersionedTransaction). The leading version byte is checked first (currently 1); unknown versions are dropped. status is exposed as the PreconfStatus enum (Failed = 0, Success = 1, Unknown = 2). Each notification exposes the decoded VersionedTransaction plus the raw transaction_bytes. See examples/websockets/preconf_subscribe.rs.

Examples

More examples of how to use the SDK can be found in the examples directory.

Error Handling

Common Error Codes

You may encounter several error codes when working with the Helius Rust SDK. Below is a table detailing some of the common error codes along with additional information to aid with troubleshooting:

Error Code Error Message More Information
401 Unauthorized This occurs when an invalid API key is provided or access is restricted
429 Too Many Requests This indicates that the user has exceeded the request limit in a given timeframe or is out of credits
5XX Internal Server Error This is a generic error message for server-side issues. Please contact Helius support for assistance

If you encounter any of these errors:

  • Refer to errors.rs for a list of all possible errors returned by the Helius client
  • Refer to the Helius documentation for further guidance
  • Reach out to the Helius support team for more detailed assistance

Result Type Alias

The SDK also has a handy type alias for Result where Result and be simplified to Result

Methods

Our SDK is designed to provide a seamless developer experience when building on Solana. We've separated the core functionality into various segments:

DAS API

  • get_asset - Gets an asset by its ID
  • get_asset_batch - Gets multiple assets by their ID
  • get_asset_proof - Gets a merkle proof for a compressed asset by its ID
  • get_asset_proof_batch - Gets multiple asset proofs by their IDs
  • get_assets_by_owner - Gets a list of assets owned by a given address
  • get_assets_by_authority - Gets a list of assets of a given authority
  • get_assets_by_creator - Gets a list of assets of a given creator
  • get_assets_by_group - Gets a list of assets by a group key and value
  • search_assets - Gets assets based on the custom search criteria passed in
  • get_signatures_for_asset - Gets transaction signatures for a given asset
  • get_token_accounts - Gets information about all token accounts for a specific mint or owner
  • get_nft_edition - Gets all the NFT editions associated with a specific master NFT

ZK Compression

  • get_compressed_account - Gets a compressed account by its address or hash
  • [get_compressed_account_proof](https://www.helius.dev/docs

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言