A Rust client library for the Titan Swap API on Solana.
Add the crate to your Cargo.toml:
[dependencies]
titan-swap-api-client = { git = "https://github.com/0xahzam/titan-swap-api-client.git" }use titan_swap_api_client::{quote::{QuoteRequest, SwapMode, Provider}, TitanClient};
use solana_sdk::pubkey::Pubkey;
use std::str::FromStr;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let auth_token = "your-auth-token".to_string();
let client = TitanClient::new(auth_token, None);
let request = QuoteRequest {
input_mint: Pubkey::from_str("So11111111111111111111111111111111111111112")?,
output_mint: Pubkey::from_str("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")?,
amount: 1_000_000_000, // 1 SOL in lamports
user_pubkey: Pubkey::from_str("YOUR_WALLET_ADDRESS")?,
max_accounts: Some(50),
swap_mode: Some(SwapMode::ExactIn),
slippage_bps: 50,
providers: Some(Provider::Titan), // Optional: force Titan routing only
..Default::default()
};
// Get a quote
let quote = client.quote(&request).await?;
println!("Quote: {} -> {}", quote.in_amount, quote.out_amount);
// Get swap instructions
let swap = client.swap("e)?;
println!("Instructions: {}", swap.instructions.len());
Ok(())
}input_mint: Input token mint addressoutput_mint: Output token mint addressamount: Amount to swap (in lamports for native SOL)user_pubkey: User's wallet public keymax_accounts: Maximum number of accounts (optional)swap_mode:SwapMode::ExactInorSwapMode::ExactOut(optional)slippage_bps: Slippage tolerance in basis points (e.g., 50 = 0.5%)providers:Some(Provider::Titan)to force Titan only routing,Nonefor best route across all providers (optional)only_direct_routes: Only direct routes (optional)excluded_dexes: Comma-separated list of DEXes to exclude (optional)
See the examples directory for a complete working example that demonstrates:
- Getting quotes
- Getting swap instructions
- Sending transactions to Solana
Run the example:
cargo run --package titan-swap-testSee examples/README.md for detailed setup instructions.
MIT