| Crates.io | fly402-client |
| lib.rs | fly402-client |
| version | 0.0.3 |
| created_at | 2025-11-01 07:30:28.623218+00 |
| updated_at | 2025-11-01 07:30:28.623218+00 |
| description | HTTP client library for the X402 payment protocol |
| homepage | https://github.com/SerPepe/402fly |
| repository | https://github.com/fly402/fly402 |
| max_upload_size | |
| id | 1911785 |
| size | 160,089 |
HTTP client library for the X402 payment protocol with automatic and explicit payment handling.
This library provides both high-level (automatic) and low-level (explicit) APIs for interacting with X402-enabled services.
Add to your Cargo.toml:
[dependencies]
402fly-client = "0.0.1"
tokio = { version = "1.35", features = ["full"] }
use 402fly_client::{Fly402AutoClient, AutoClientOptions};
use solana_sdk::signer::keypair::Keypair;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let keypair = Keypair::new();
let client = Fly402AutoClient::new(
keypair,
None, // use default RPC
AutoClientOptions::default(),
);
// Request is automatically handled - client pays if needed
let response = client.get("https://api.example.com/premium").await?;
let body = response.text().await?;
println!("{}", body);
Ok(())
}
use 402fly_client::Fly402Client;
use solana_sdk::signer::keypair::Keypair;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let keypair = Keypair::new();
let client = Fly402Client::new(keypair, None)?;
// Make request
let response = client.get("https://api.example.com/premium").await?;
// Check for payment requirement
if client.is_payment_required(&response) {
let payment_request = client.parse_payment_request(&response).await?;
let auth = client.create_payment(&payment_request).await?;
// Retry with payment
let response = client.get_with_auth(
"https://api.example.com/premium",
auth
).await?;
println!("{}", response.text().await?);
}
Ok(())
}
pub struct AutoClientOptions {
pub max_payment_amount: String, // Default: "10.0"
pub auto_retry: bool, // Default: true
pub max_retries: u32, // Default: 3
}
For full documentation, visit: https://402fly.github.io/docs
MIT License - See LICENSE file for details.
402fly-core - Core protocol library402fly-rocket - Rocket server integration402fly-actix - Actix Web server integration