| Crates.io | fly402-actix |
| lib.rs | fly402-actix |
| version | 0.0.3 |
| created_at | 2025-11-01 07:31:43.660162+00 |
| updated_at | 2025-11-01 07:31:43.660162+00 |
| description | Actix Web framework integration for X402 payment protocol |
| homepage | https://github.com/SerPepe/402fly |
| repository | https://github.com/fly402/fly402 |
| max_upload_size | |
| id | 1911787 |
| size | 155,489 |
Actix Web framework integration for the X402 payment protocol.
This library provides extractors and utilities for implementing payment-protected endpoints in Actix Web applications.
Add to your Cargo.toml:
[dependencies]
402fly-actix = "0.0.1"
actix-web = "4.4"
tokio = "1.35"
use actix_web::{get, web, App, HttpServer, HttpResponse};
use 402fly_actix::{
Fly402Config, X402State, PaymentExtractor, PaymentRequirement,
create_payment_request, payment_required_response
};
#[get("/premium")]
async fn premium_content(
state: web::Data<X402State>,
auth: Option<PaymentExtractor>,
) -> HttpResponse {
match auth {
Some(_) => {
// Payment verified
HttpResponse::Ok().json("Premium content here!")
}
None => {
// No payment, return 402
let requirement = PaymentRequirement::new("0.10")
.with_description("Access to premium content");
let payment_request = create_payment_request(&state.config, &requirement, "/premium");
payment_required_response(payment_request)
}
}
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let config = Fly402Config {
payment_address: "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU".to_string(),
token_mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v".to_string(),
network: "solana-devnet".to_string(),
rpc_url: None,
auto_verify: true,
};
let state = web::Data::new(X402State { config });
HttpServer::new(move || {
App::new()
.app_data(state.clone())
.service(premium_content)
})
.bind("127.0.0.1:8080")?
.run()
.await
}
pub struct Fly402Config {
pub payment_address: String, // Where payments go
pub token_mint: String, // Token to accept (e.g., USDC)
pub network: String, // Solana network (mainnet, devnet, testnet)
pub rpc_url: Option<String>, // Custom RPC endpoint
pub auto_verify: bool, // Auto-verify payments
}
let requirement = PaymentRequirement::new("1.00")
.with_description("Premium API access")
.with_expires_in(600); // Expires in 10 minutes
For full documentation, visit: https://402fly.github.io/docs
MIT License - See LICENSE file for details.
402fly-core - Core protocol library402fly-client - HTTP client library402fly-rocket - Rocket Web integration