11 releases (1 stable)
new 2.0.1 | Jan 25, 2025 |
---|---|
2.0.0 |
|
0.4.3 | Jul 21, 2024 |
0.4.1 | Jun 30, 2024 |
0.1.0 | Apr 25, 2024 |
#3 in Magic Beans
93 downloads per month
2MB
34K
SLoC
Overview
fireblocks_sdk
is an async library for the Fireblocks API
!!!! Note this is community driven project and not affiliated with Fireblocks !!!!!
Getting Started
cargo install fireblocks-sdk
See developer portal and sign up for a sandbox account
Quick Start
use {
fireblocks_sdk::{
apis::vaults_api::{GetPagedVaultAccountsParams, GetVaultAccountParams},
ClientBuilder,
},
std::{fs::File, io::Read, time::Duration},
};
fn load_secret() -> anyhow::Result<Vec<u8>> {
match std::env::var("FIREBLOCKS_SECRET").ok() {
Some(secret) => Ok(secret.into_bytes()),
None => {
let secret = std::env::var("FIREBLOCKS_SECRET_FILE")
.expect("failed find secret key in FIREBLOCKS_SECRET or FIREBLOCKS_SECRET_FILE");
let mut file = File::open(secret).expect("file not found");
let mut secret: String = String::new();
file.read_to_string(&mut secret)
.expect("something went wrong reading the file");
Ok(secret.into_bytes())
}
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let api_key = std::env::var("FIREBLOCKS_API_KEY")?;
let secret = load_secret()?;
let client = ClientBuilder::new(&api_key, &secret)
.with_sandbox()
.with_timeout(Duration::from_secs(10))
.with_connect_timeout(Duration::from_secs(5))
.build()?;
let id = String::from("0");
let params = GetVaultAccountParams {
vault_account_id: id.clone(),
};
let vault_account = client.vaults_api().get_vault_account(params).await?;
println!("vault account: {vault_account:#?}");
let params = GetPagedVaultAccountsParams::builder().limit(50.0).build();
let vault_accounts = client.vaults_api().get_paged_vault_accounts(params).await?;
println!("vault accounts: {:#?}", vault_accounts);
Ok(())
}
APIs
The fireblocks_sdk::Client is a small wrapper to the auto-generate fireblocks_sdk::apis::ApiClient using openapi generator.
use crate::fireblocks_sdk::apis::Api;
use fireblocks_sdk::Client;
fn demo(client: Client) {
// Access to generated API client
let api_client = client.apis();
// External Wallet Api (whitlisted)
let external_wallet_api = api_client.whitelisted_external_wallets_api();
}
Bon builder
Parameters to APIs use bon to all API endpoints (both query and body)
Caveats
The openapi-generator decided that all integers are floats. Annoying yes, but it is what it is.
Development
Create a .env file
cp .env-sameple .env
Edit .env and configure your API and secret key in FIREBLOCKS_SECRET or FIREBLOCKS_SECRET_FILE. You also need to create some whitlisted (see tests/wallets.rs for details)
Run tests:
cargo test
Run a single test:
cargo test --test wallets
Docs
Code was generatered by Fireblocks openapi spec using openapi-generator with this config
See docs
Dependencies
~12–25MB
~375K SLoC