| Crates.io | green-rs |
| lib.rs | green-rs |
| version | 0.1.3 |
| created_at | 2025-07-18 21:03:10.600404+00 |
| updated_at | 2025-07-18 22:06:56.496954+00 |
| description | A Rust implementation to interface into the Blockstream green-cli client for Bitcoin and the Liquid Network |
| homepage | |
| repository | https://github.com/gmikeska/green-rs |
| max_upload_size | |
| id | 1759679 |
| size | 216,123 |
Green.rs is a Rust library for interacting with the Green API to handle cryptocurrency transactions. It provides a Builder pattern to facilitate transaction creation, signing, and broadcasting.
To use Green.rs in your project, add the following to your Cargo.toml:
[dependencies]
green-rs = "0.1"
use green_rs::client::GreenClient;
use green_rs::api::wallet::WalletExt;
use green_rs::api::address::AddressApi;
use green_rs::api::builder::GetReceiveAddressBuilder;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a synchronous client
let client = GreenClient::new();
// Get wallet balance
let balance = client.get_balance()?;
println!("Balance: {} BTC satoshis", balance.get_btc_balance());
// Generate a new address
let address_request = GetReceiveAddressBuilder::new()
.subaccount(0)
.build();
let address = client.get_new_address(address_request)?;
println!("New address: {}", address.address);
Ok(())
}
use green_rs::client::AsyncGreenClient;
use green_rs::api::wallet::AsyncWalletExt;
use green_rs::api::address::AsyncAddressApi;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AsyncGreenClient::new();
// Concurrent operations
let (balance, fees) = tokio::join!(
client.get_balance(),
client.get_fee_estimates()
);
println!("Balance: {} sats", balance?.get_btc_balance());
println!("Fast fee: {} sat/vB", fees?.get_fee_for_target(1).unwrap_or(0));
Ok(())
}
use green_rs::api::transaction::TxBuilder;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let tx = TxBuilder::new()
.add_output("bc1qxy2kg...".to_string(), 100000)
.add_output("bc1qab3de...".to_string(), 50000)
.set_fee_rate(10)
.set_subaccount(0)
.dump()?
.sign()?
.send()?;
println!("Transaction sent: {}", tx);
Ok(())
}
The examples/ directory contains complete working examples:
basic_sync.rs - Synchronous client usage for getting balance and generating addressesbasic_async.rs - Asynchronous client usage with Tokio, including concurrent operationstx_builder.rs - Transaction builder pattern demonstration with multiple outputsRun examples with:
cargo run --example basic_sync
cargo run --example basic_async
cargo run --example tx_builder
For detailed API documentation, please visit docs.rs/green-rs.
We welcome contributions! Please see CONTRIBUTING.md for guidelines on how to contribute to this project.
If you discover a security vulnerability, please email security@yourdomain.com instead of using the issue tracker.
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.