10 releases
Uses new Rust 2024
| 0.1.4 | Apr 2, 2026 |
|---|---|
| 0.1.3 | Apr 1, 2026 |
| 0.1.2 | Mar 31, 2026 |
| 0.0.5 | Mar 28, 2026 |
#33 in #market
419 downloads per month
25KB
711 lines
legend-client
Rust client library for the Legend API. This is the same client that powers legend-cli.
Install
[dependencies]
legend-client = "0.0.1"
tokio = { version = "1", features = ["full"] }
Usage
use legend_client::{LegendPrime, Config};
let client = LegendPrime::new(Config {
query_key: std::env::var("LEGEND_QUERY_KEY").unwrap(),
base_url: None, // defaults to https://prime-api.legend.xyz
verbose: false,
});
// List accounts
let accounts = client.accounts.list().await?;
// View portfolio
let folio = client.accounts.folio("acc_xxx", &Default::default()).await?;
// Create and execute a plan
use legend_client::EarnParams;
let plan = client.plan.earn("acc_xxx", &EarnParams {
amount: "1000".into(),
asset: "usdc".into(),
network: "base".into(),
protocol: "aave_v3".into(),
market: None,
}).await?;
let digest = plan.digest().expect("missing digest");
All plan types are supported: earn, withdraw, swap, transfer, borrow, repay, claim_rewards, loop_long, unloop_long, add_backing, withdraw_backing, migrate, swap_and_supply, reinvest_rewards.
Error handling
use legend_client::LegendPrimeError;
match client.accounts.get("acc_xxx").await {
Ok(account) => println!("{}", account.account_id),
Err(LegendPrimeError::Api { code, message, status }) => {
eprintln!("API error ({status}): [{code}] {message}");
}
Err(e) => eprintln!("{e}"),
}
License
MIT
Dependencies
~6–13MB
~208K SLoC