Rust
Install and make your first Mainly request with the Rust SDK.
The official Rust SDK is published on crates.io as
mainly.
Install
cargo add mainlyThe SDK uses async Rust. If your project does not already include Tokio, add it as well:
cargo add tokio --features macros,rt-multi-threadMake a request
Create one client and reuse it across requests:
use mainly::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ClientConfig {
token: Some(std::env::var("MAINLY_API_KEY")?),
..Default::default()
};
let client = Mainly::new(config)?;
let balance = client
.solana
.wallets
.get_balance(
"9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
&SolanaWalletsGetBalanceQueryRequest::default(),
None,
)
.await?;
println!("Balance: {} SOL", balance.sol);
Ok(())
}The token field sends your key as an Authorization: Bearer header.
Choose a network
Resources are grouped by chain and network on the client:
client.solana;
client.solana_devnet;
client.ethereum;
client.ethereum_sepolia;For example, change client.solana to client.solana_devnet to make the same
request against Solana devnet.
Handle errors and retries
Every request returns a Result<_, ApiError>. Match on ApiError when you
need to handle transport and API failures differently. The SDK automatically
retries retryable failures with exponential backoff.
Pass RequestOptions as the final method argument to customize an individual
request:
let options = RequestOptions::new()
.max_retries(1)
.timeout_seconds(10);Next, browse the API reference or see the complete Rust SDK source.