Documentation Index
Fetch the complete documentation index at: https://www.helius.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
Helius Rust SDK为所有Helius API提供异步Rust绑定,非常适合高性能代理工作负载。
- Crate:
helius (crates.io)
- Version: 1.x (使用
solana-client 3.0, solana-sdk 3.0)
- Runtime: 异步 (
tokio 1.x)
- Rust: 1.85+ (edition 2021)
- HTTP Client:
reqwest
- License: MIT
[dependencies]
helius = "1.0.0"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
solana-sdk = "3.0.0"
crate默认使用native-tls。对于纯Rust TLS(在OpenSSL不可用时有用),使用:
helius = { version = "1.0.0", default-features = false, features = ["rustls"] }
快速入门
use helius::error::Result;
use helius::types::*;
use helius::Helius;
#[tokio::main]
async fn main() -> Result<()> {
let helius = Helius::new("YOUR_API_KEY", Cluster::MainnetBeta)?;
// Get all NFTs owned by a wallet
let assets = helius.rpc().get_assets_by_owner(GetAssetsByOwner {
owner_address: "86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY".to_string(),
page: 1,
limit: Some(50),
..Default::default()
}).await?;
// Get transaction history (with token account activity)
let txs = helius.rpc().get_transactions_for_address(
"86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY".to_string(),
GetTransactionsForAddressOptions {
limit: Some(100),
transaction_details: Some(TransactionDetails::Full),
filters: Some(GetTransactionsFilters {
token_accounts: Some(TokenAccountsFilter::BalanceChanged),
..Default::default()
}),
..Default::default()
},
).await?;
// Send a transaction via Helius Sender (ultra-low latency)
let sig = helius.send_smart_transaction_with_sender(
SmartTransactionConfig {
create_config: CreateSmartTransactionConfig {
instructions: vec![transfer_instruction],
signers: vec![wallet_signer],
..Default::default()
},
..Default::default()
},
SenderSendOptions {
region: "US_EAST".to_string(),
..Default::default()
},
).await?;
Ok(())
}
客户端构造器
Helius::new — 基本同步客户端
let helius = Helius::new("YOUR_API_KEY", Cluster::MainnetBeta)?;
最简单的构造器。不需要.await。提供RPC方法、webhook、增强型交易、智能交易和钱包API。不支持异步Solana客户端或WebSocket。
Helius::new_async — 功能齐全的异步客户端
let helius = Helius::new_async("YOUR_API_KEY", Cluster::MainnetBeta).await?;
推荐用于生产环境。包括异步Solana RPC客户端和增强型WebSocket流。需要.await,因为它建立了WebSocket连接。
Helius::new_with_url — 自定义RPC端点
let helius = Helius::new_with_url("http://localhost:8899")?;
适用于专用RPC节点、代理或本地开发。不需要API密钥。
HeliusBuilder — 高级配置
use helius::HeliusBuilder;
let helius = HeliusBuilder::new()
.with_api_key("YOUR_API_KEY")?
.with_cluster(Cluster::MainnetBeta)
.with_async_solana()
.with_websocket(None, None)
.with_commitment(CommitmentConfig::confirmed())
.build()
.await?;
HeliusFactory — 多集群
let factory = HeliusFactory::new("YOUR_API_KEY");
let devnet_client = factory.create(Cluster::Devnet)?;
let mainnet_client = factory.create(Cluster::MainnetBeta)?;
访问嵌入式Solana客户端
helius.connection() // Sync SolanaRpcClient (Arc)
helius.async_connection()? // Async SolanaRpcClient (requires new_async or HeliusBuilder)
helius.ws() // Enhanced WebSocket (Option)
helius.rpc() // Helius RpcClient (Arc)
helius.config() // Config (Arc)
深入探讨
docs.rs
docs.rs 上的完整 API 文档
迁移指南 (0.x 到 1.0)
从 solana-sdk 1.x 升级到 3.0