Crate stellar_rs
source ·Expand description
Stellar Horizon SDK for Rust
This Rust library provides a user-friendly interface to the Stellar Horizon API,
allowing developers to easily query and transact on the Stellar network. Centered
around the HorizonClient
, the SDK abstracts the underlying HTTP request and response
mechanisms into a set of simple, high-level methods.
The SDK is designed with a focus on developer experience, providing clear abstractions, sensible defaults, and streamlined error handling.
Status
The SDK is under active development. It is functional but should be considered a work-in-progress. Features may be added or changed, and the SDK may evolve before stabilization.
Supported endpoints:
- Accounts
- Assets
- Claimable balance
- Ledgers
Endpoints on the roadmap:
- Effects
- Fee stats
- Liquidity pools
- Offers
- Operations
- Orderbook
- Paths
- Payments
- Trade aggregations
- Trades
- Transactions
Example Usage
The following example demonstrates how to use the HorizonClient
to retrieve a list
of accounts with a specific signer:
use stellar_rs::horizon_client::HorizonClient;
use stellar_rs::accounts::prelude::{AccountsRequest, AccountsResponse};
use stellar_rs::models::{Request, Response};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the Horizon client with the testnet server
let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org".to_string())?;
// Create a request to fetch accounts with a specific signer
let accounts_request = AccountsRequest::new()
.set_signer_filter("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7")?
.set_limit(10)?;
// Perform the request using the Horizon client
let accounts_response =
horizon_client.get_account_list(&accounts_request)
.await;
// Check for success and handle the response or error
match accounts_response {
Ok(response) => {
// Process the response
},
Err(e) => {
// Handle the error
}
}
Ok(())
}
This example initializes a HorizonClient
, constructs an AccountsRequest
to filter
accounts by signer, and calls get_account_list
to retrieve the relevant data.
The result is then handled in a match expression, demonstrating the SDK’s straightforward
error handling.
Visit the documentation for HorizonClient
and endpoint-specific request and response
types for more examples and detailed usage instructions.
Modules
- Provides
Request
andResponse
structs for retrieving accounts. - Provides
Request
andResponse
structs for retrieving assets. - Provides
Request
andResponse
structs for retrieving claimable balances. - Client for calling the Stellar Horizon API
- Provides
Request
andResponse
structs for retrieving ledgers. - Contains core data structures and traits.
Enums
- Represents the types of assets in the Stellar network.