| Crates.io | openlibx402-client |
| lib.rs | openlibx402-client |
| version | 0.0.3 |
| created_at | 2025-10-31 14:14:29.018233+00 |
| updated_at | 2025-10-31 14:32:30.037504+00 |
| description | HTTP client library for the X402 payment protocol |
| homepage | https://openlib.xyz |
| repository | https://github.com/openlibx402/openlibx402 |
| max_upload_size | |
| id | 1910110 |
| size | 160,153 |
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]
openlibx402-client = "0.0.1"
tokio = { version = "1.35", features = ["full"] }
use openlibx402_client::{X402AutoClient, AutoClientOptions};
use solana_sdk::signer::keypair::Keypair;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let keypair = Keypair::new();
let client = X402AutoClient::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 openlibx402_client::X402Client;
use solana_sdk::signer::keypair::Keypair;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let keypair = Keypair::new();
let client = X402Client::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://openlibx402.github.io/docs
MIT License - See LICENSE file for details.
openlibx402-core - Core protocol libraryopenlibx402-rocket - Rocket server integrationopenlibx402-actix - Actix Web server integration