Installation
Add Anya to your Rust project by including it in your Cargo.toml:
[dependencies]
anya = "0.2.0"
tokio = { version = "1.34", features = ["full"] }
anyhow = "1.0"
Prerequisites
- Rust 1.70 or later
- Bitcoin Core (optional, for full node functionality)
- Windows 10/11 or compatible OS
Configuration
Create a configuration file anya.toml in your project root:
[bitcoin]
network = "testnet" # or "mainnet"
rpc_url = "http://127.0.0.1:8332"
rpc_user = "your_rpc_user"
rpc_password = "your_rpc_password"
[security]
encryption_type = "aes256gcm"
key_derivation = "pbkdf2"
[storage]
path = "./data"
backup_enabled = true
Basic Usage
Here's a simple example of using Anya in your Rust application:
use anya::Anya;
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
// Initialize Anya
let anya = Anya::new().await?;
// Initialize the system
anya.init().await?;
// Create a new Bitcoin wallet
let wallet = anya.create_wallet("my_wallet").await?;
// Get wallet balance
let balance = wallet.get_balance().await?;
println!("Wallet balance: {} BTC", balance);
// Create a new transaction
let tx = wallet
.create_transaction("tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx", 0.001)
.await?;
// Sign and broadcast the transaction
let tx_id = wallet.send_transaction(tx).await?;
println!("Transaction sent! ID: {}", tx_id);
Ok(())
}
Error Handling
Anya uses the anyhow crate for error handling. All errors are properly wrapped and contain context:
use anya::Anya;
use anyhow::Result;
async fn handle_errors() -> Result<()> {
let anya = Anya::new().await?;
match anya.init().await {
Ok(_) => println!("Initialization successful"),
Err(e) => eprintln!("Error during initialization: {:#}", e),
}
Ok(())
}