use dotenvy::dotenv;
use starknet::core::types::Felt;
use starkzap_rs::{
Amount, OnboardConfig, Recipient, StarkZap, StarkZapConfig, signer::StarkSigner,
tokens::sepolia, wallet::DeployPolicy,
};
use tracing::info;
#[tokio::main]
async fn main() -> starkzap_rs::error::Result<()> {
dotenv().ok();
tracing_subscriber::fmt()
.with_env_filter("info,starkzap_rs=info")
.init();
let sdk = StarkZap::new(StarkZapConfig::sepolia());
let signer = StarkSigner::new(
&std::env::var("PRIVATE_KEY").expect("PRIVATE_KEY not set"),
&std::env::var("ACCOUNT_ADDRESS").expect("ACCOUNT_ADDRESS not set"),
)?;
let wallet = sdk.onboard(OnboardConfig::Signer(signer)).await?;
info!("Wallet: {}", wallet.address_hex());
wallet.ensure_ready(DeployPolicy::IfNeeded).await?;
let strk = sepolia::strk();
let balance = wallet.balance_of(&strk).await?;
info!("STRK balance: {}", balance);
let recipient_hex = std::env::var("RECIPIENT_ADDRESS").expect("RECIPIENT_ADDRESS not set");
let recipient = Felt::from_hex(&recipient_hex).expect("Invalid RECIPIENT_ADDRESS");
let amount = Amount::parse("0.01", &strk)?;
info!("Transferring {} to {}", amount, recipient_hex);
let tx = wallet
.transfer(&strk, vec![Recipient::new(recipient, amount)])
.await?;
info!("Submitted: {}", tx);
let receipt = tx.wait().await?;
info!("Confirmed in block {}", receipt.block.block_number());
Ok(())
}